多年来我一直在问自己这个问题,但我一直认为除了将所有命令放入脚本并执行它之外没有其他解决方案:nohup . ./multiplecommands.sh &
我不知道我为什么不早点尝试,但至少这个小测试运行良好。并且外壳在错误后不会停止。如果你替换;
by&&
我认为它会
blup$ nohup echo ett > ~/tmp/nohup_on_multiple_commands_test_sep_thru_semicolon ; echo tvaa >> ~/tmp/nohup_on_multiple_commands_test_sep_thru_semicolon ; echo tre >> ~/tmp/nohup_on_multiple_commands_test_sep_thru_semicolon ; echo fyra >> ~/tmptypo/nohup_on_multiple_commands_test_sep_thru_semicolon ; echo fem >> ~/tmp/nohup_on_multiple_commands_test_sep_thru_semicolon ; cat ~/tmp/nohup_on_multiple_commands_test_sep_thru_semicolon &
nohup: ignoring input and redirecting stderr to stdout
bash: /home/blubber/tmptypo/nohup_on_multiple_commands_test_sep_thru_semicolon: No such file or directory
[3] 27136
blub$ ett #<-- this looks a bit ugly, though, but ignore the additional prompt now.
tvaa
tre
fem
[3]+ Done cat ~/tmp/nohup_on_multiple_commands_test_sep_thru_semicolon
blub$ cat ~/tmp/nohup_on_multiple_commands_test_sep_thru_semicolonett
tvaa
tre
fem
blub$
ERGO:echo fyra
没有被处决,但echo fem
被处决了。
用AND
=&&
而不是同样的事情;
blub2$ nohup echo one > ~/tmp/nohup_on_multiple_commands_test_sep_thru_semicolon && echo two >> ~/tmp/nohup_on_multiple_commands_test_sep_thru_semicolon && echo threefour >> ~/tmptypo/nohup_on_multiple_commands_test_sep_thru_semicolon && echo five >> ~/tmp/nohup_on_multiple_commands_test_sep_thru_semicolon ; cat ~/tmp/nohup_on_multiple_commands_test_sep_thru_semicolon &nohup: ignoring input and redirecting stderr to stdout
bash: /home/blubber2/tmptypo/nohup_on_multiple_commands_test_sep_thru_semicolon: No such file or directory
[3] 28744
blub$ one
two
[3]+ Done cat ~/tmp/nohup_on_multiple_commands_test_sep_thru_semicolon
blub$ cat ~/tmp/nohup_on_multiple_commands_test_sep_thru_semicolon
one
two
blub$
ERGO:如果您需要失败后退出,请使用&&
而不是;