bash - bash 文件中的事件 .bashrc 设置

标签 bash

在 .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/

相关文章:

json - 根据其中一个属性删除重复的 JSON 文件

bash - 在没有 nc 的情况下获取 memcached 统计信息很热吗?

linux - 评论 bash 脚本?

bash - 当我的单词包含冒号时如何给出正确的选项卡完成建议

bash - 如何在 bash for 循环中内联字符串数组?

linux - 通过 ssh 连接找不到 Bash、别名/自定义函数

linux - 如何检查我有权读取目录中的哪些文件?

bash - 调用名称存储在 bash 变量中的函数

linux - 从 Bash 脚本中的文件参数打印权限

regex - 如何使用sed替换字符串中间的匹配字符