我的.bashrc文件导出一个叫做lookup的函数:
lookup() { grep -r -ne "$1" * | grep -v "TAGS:" | grep -v "tags:" } export -f lookup
我可以在shell中使用该函数。 但是如果我把它放在这样的脚本中:
#!/bin/bash lookup "foo"
并运行该脚本,然后打击报告“找不到命令”进行lookup 。 这个曾经工作过一段时间。 我强烈怀疑这是停止工作后,我的系统上的bash安全更新(可能与shellshock / bashdoor有关?)我的bash版本是4.1.10(1)在openSUSE 11.4
检查http://www.gnu.org/software/bash/manual/bashref.html#Bash-Startup-Files
以非交互方式调用
例如,当Bash以非交互方式启动时,为了运行一个shell脚本,例如它在环境中查找variablesBASH_ENV,如果它出现在那里,则展开它的值,并且使用展开后的值作为文件的名字来读取和执行。
具体来说,〜/ .bashrc,〜/ .profile,〜/ .bash_profile都不是来源的。 〜/ .bashrc只有在shell是一个交互式shell时才会被调用。
你有几个select:
显式地input你的.bashrc
#!/bin/bash . ~/.bashrc lookup "foo"
开始与交互式标志bash
#!/bin/bash -i lookup "foo"
启动脚本时设置BASH_ENVvariables:
BASH_ENV=$HOME/.bashrc /path/to/my/script