我有一个问题,我的 cron 脚本没有加载环境变量,所以我添加了以下行:
#!/bin/sh
bash /root/.bash_profile
Run Code Online (Sandbox Code Playgroud)
这似乎没有效果,并且路径变量设置不正确。如何运行 bash_profile 脚本
bash /root/.bash_profile
将创建一个新bash
进程,运行该文件(我假设在执行此操作时设置了您的 env 变量),然后退出,并使用这些新设置的 env 变量。
试试. /root/.bash_profile
。或者source /root/.bash_profile
。这将在当前 bash 进程中执行该文件,因此您的 env 变量将可用于当前进程。
如果您要进行 bash 样式的调用,您可能还想使用#!/bin/bash
代替#!/bin/sh
。