如何在 OSX 中获取 .bash_profile 中的外部文件?

How to source an external file in .bash_profile in OSX?

我在我的 .bash_profile 文件中定义了一些别名,这些别名按预期工作。例如

alias python-server="python -m SimpleHTTPServer 7070"

而且,当我打开新终端时,输入 python-server 会打开一个 python 服务器,当前目录为根目录(或“/”)。

但是我有大约 10 个别名,我想备份这些别名所以我想创建一个包含这些别名的外部文件,并试图从 .bash_profile 中获取该文件,就像这样

source ~/personal/Dropbox/scripts/aliases.sh

但是当我打开新终端时收到错误

Last login: Fri Dec 11 23:16:28 on ttys004
: No such file or directory
: command not found
: command not found

但是,我的命令运行良好。例如python-server 按预期从外部文件工作。我只是想知道这个错误的原因,可能是更好的实现方式。

.bash_profile

的内容
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm

# Load aliases
source ~/personal/repo/scripts/aliases

PATH=$PATH:$HOME/personal/repo/scripts/commands
PATH=$PATH:$HOME/personal/repo/scripts/git
export PATH

别名文件的内容

#!/bin/bash

# ---------------
# Load my aliases
# ---------------
alias python-server="python -m SimpleHTTPServer 7070"

PS:现在,我从别名文件中删除了注释,它在打开新终端时将 : command not found 的计数从 2 减少到 1

从上面的文件中删除 'control codes',即“\r”。

如何检查:

  cat ~/.bashprofile  | od -c ## see any '\r's?

使用'vi'或'vim'编辑文件或'clean'使用'tr',即

tr -d '\r' ~/.bashprofile > ~/.bashprofile.mod  
cp ~/.bashprofile.mod ~/.bashprofile