変える:
nohup ./script.sh &
tail -f nohup.out
私がしたい:
nohup ./script.sh &; tail -f nohup.out
ただし、nohupを呼び出した後にEnterキーを押す必要があるため、動作しません。
ベストアンサー1
bash
、 、dash
でコマンドラインを終了するため、pdksh
次は行われません。&
nohup ./script.sh
;
それで;
あなたは得るでしょう
bash: syntax error near unexpected token `;'
;
コマンドを個別に実行しようとすると得られるのと同じです。
あなたのコマンドksh93
によるとzsh
うまく動作します。
他のシェルの場合は、bash
次のようにします。
$ nohup ./script.sh & tail -f nohup.out
ただし、パイプラインを実行するときと同様に、パイプラインのさまざまな部分が(ほぼ)同時に開始されます。tail
ファイルが存在する前に起動すると、次nohup.out
のエラーが原因で失敗します。
tail: nohup.out: No such file or directory
この問題を解決するには:
$ nohup ./script.sh & sleep 1 && tail -f nohup.out
または待つのが好きではない場合:
$ nohup ./script.sh & while ! test -f nohup.out; do :; done && tail -f nohup.out
または以下のコメントで「VPfB」が指摘したように、
$ nohup ./script.sh >output & tail -f output