我有一个问题,我的cron脚本不加载环境variables,所以我添加了以下行:
#!/bin/sh bash /root/.bash_profile
这似乎没有效果,pathvariables没有正确设置。 我如何运行bash_profile脚本
bash /root/.bash_profile将创build一个新的bash进程,运行该文件(我假设在设置你的envvariables的同时),然后退出,把这些新设置的envvariables。
试试. /root/.bash_profile . /root/.bash_profile 。 或source /root/.bash_profile 。 这将在当前bash进程中执行该文件,因此您的envvariables将可用于当前进程。
如果你打算使用bash风格的调用,你也可以使用#!/bin/bash而不是#!/bin/sh 。
. /root/.bash_profile . /root/.bash_profile或source /root/.bash_profile 。 它说在当前shell中运行该文件。 你的方法在s subshell中运行.bash_profile在子shell中设置variables,然后这个子shell退出,并带上这些variables。
如果要将variables包含在.bash_profile文件中,则需要将其源代码放在脚本中。
简单地执行脚本将不包含导出的variables。