nohup:无法运行命令“.”:权限被拒绝

use*_*165 8 shell source alias nohup

我尝试使用以下方法执行我的脚本:

nohup . test.sh
Run Code Online (Sandbox Code Playgroud)

nohup . ./test.sh
Run Code Online (Sandbox Code Playgroud)

但是,我得到了:nohup: failed to run command `.': Permission denied每次。

我真正想做的是在我的脚本中能够调用我使用别名的命令,但它只适用于“ . test.sh”或“ . ./test.sh”,而不是“ ./test.sh”或“ sh ./test.sh”,因为我得到“找不到命令”。但我希望能够用“nohup”运行它。

Gil*_*il' 19

nohup运行一个可执行文件。您需要向它传递一个外部命令,即一个可执行文件。您不能调用nohupshell 构造,例如别名、函数或内置函数。nohup运行一个新进程,它不会在现有的 shell 进程中运行某些东西(因为nohup它本身是一个单独的进程),所以nohup . …没有意义。

nohup ./test.sh是使用 nohup 运行 shell 脚本的正确方法。确保脚本正确以 shebang 行 ( #!/bin/sh)开头并且文件是可执行的 ( chmod +x ./test.sh)。