我一直在問自己這個多年,但我總覺得有沒有其他解決辦法不是將所有命令到一個腳本並執行它想:nohup . ./multiplecommands.sh &
我不知道爲什麼我沒有早嘗試,但至少這個小小的測試工作得很好。 並且在發生錯誤後shell不會停止。 如果更換;
通過&&
我認爲它會雖然
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同樣的事情:如果你需要退出,之後失效,然後使用&&
代替;
來源
2014-01-29 16:09:18
AMo
'nohup'能很好地工作分號:請參閱http://people.ucalgary.ca/~wellings/tipspit/nohup.html您可以使用不同的命令創建測試用例(如創建五個後續文件)?另外,我認爲如果其中一個命令返回一個錯誤,其他命令將不會被執行(雖然不知道,但Linux專家需要確認) – 2010-08-11 09:29:18
我認爲它也可以工作(它工作正常用一個命令W/O分號),但它實際上並沒有... 所以我的PHP腳本等待命令完成,而不是像以前繼續... 順便說一句,我認爲你是對的關於以下錯誤時不執行命令。 – Michael27 2010-08-11 09:56:32