在 .bashrc 中,我没有使用默认的 python,而是将“python”指向我自己的 python 版本。但是,当我编写 bash 脚本并在其中调用 python 时,它仍然使用默认的 python。为什么会这样,如何设置它以便我不必将“source ~/.bashrc”添加到每个 sh 文件中?谢谢
[yl@chh test]$ more test.sh
echo `which python`
[yl@chh test]$ sh test.sh
/usr/bin/python
[yl0@chh test]$ which python
alias python='~/tools/Python-2.7.3/python'
~/tools/Python-2.7.3/python
最佳答案
来自 bash
手册页:
Aliases are not expanded when the shell is not interactive, unless the expand_aliases shell option is set using shopt (see the description of shopt under SHELL BUILTIN COMMANDS below).
为此目的,更改 PATH 可能比使用别名更好。
关于bash - bash 文件中的事件 .bashrc 设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13198917/