如何使用 nohup 执行多个命令

Ehs*_*san 49 command-line shell nohup

我需要使用nohup. 每个命令都应该在上一个命令之后执行。

我以这个命令为例:

nohup wget $url && wget $url2 > /dev/null 2>&1 &
Run Code Online (Sandbox Code Playgroud)

但是,该命令不起作用。

为此我应该使用什么命令?

jw0*_*013 71

把它包起来sh -c

nohup sh -c 'wget "$0" && wget "$1"' "$url1" "$url2" > /dev/null &
Run Code Online (Sandbox Code Playgroud)

  • 当我启动 nohup 时,我得到“nohup: ignoring input and redirecting stderr to stdout”,所以“2>&1”不是多余的吗? (2认同)

小智 8

在没有任何 nohup 的单独 shell 文件(例如 command.sh)中创建命令列表不是更简单吗?

然后你打电话:

nohup bash command.sh
Run Code Online (Sandbox Code Playgroud)


jan*_*nos 5

其他人已经回答了nohup。作为一个实用的旁注:我建议在一个screentmux会话中做这种事情。这样您就可以断开连接,然后稍后重新连接并查看输出和最终结果。

  • 这个答案非常适合交互式场景,但对脚本或自动化没有意义。 (2认同)