[英]Source / Alias not Permanent in Mac .bashrc
I have a .sources
symlink pointing to a directory with files I wish to source when Terminal is opened. 我有一个
.sources
符号链接,该链接指向一个目录,该目录包含在打开终端时希望提供的文件。
In my .bashrc
file, which is sourced from ~/.bash_profile
, I have the following code 在来自
~/.bash_profile
.bashrc
文件中,我有以下代码
sourcesDir=$HOME/.sources
ls -B $sourcesDir | while read filename; do
echo "source $sourcesDir/$filename"
source $sourcesDir/$filename
done
When I start Terminal, I get the following output 当启动终端时,我得到以下输出
source /Users/merlinpatterson/.sources/bash_aliases
source /Users/merlinpatterson/.sources/git_completion.bash
source /Users/merlinpatterson/.sources/git_prompt.sh
source /Users/merlinpatterson/.sources/meteor.sh
However, when I run alias
, none of the aliases show up. 但是,当我运行
alias
,没有任何别名出现。 Any variables exported are blank. 导出的所有变量均为空白。 And
__git_ps1
is not found. 并且
__git_ps1
。
If I run the above commands after starting the Terminal, everything works, so the files themselves are fine. 如果我在启动终端后运行上述命令,则一切正常,因此文件本身也很好。
Why are the results of source
not staying around in the Terminal? 为什么
source
的结果没有留在终端中?
The while
loop runs in a subshell, not your current shell. while
循环在子shell中运行,而不是在当前shell中运行。 Use instead 改用
for filename in "$sourcesDir"/*; do
source "$filename"
done
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.