我正在写一个 bash 文件。我需要从我的 bash 文件启动 apachectl
。所以我写道:
apachectl start
当我用 root 运行它时,发生错误:
apachectl: command not found
我搜索了一下,发现我应该是 super user su -
而不是 su
现在,我想知道:
为什么会出现这个错误?
如何使用
su
运行它?
最佳答案
在 shell 脚本中,你应该使用完整路径来执行命令,除非 $PATH 中已经包含可执行文件的目录。 例如,查找 apachectl 二进制文件所在的位置:
which apachectl
或
whereis apachectl
你会得到类似的东西:
/usr/local/sbin/apachectl
所以,使用它。
关于linux - 从 bash 启动 apachectl,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9348204/