3
$ cat test1.sh
#!/bin/bash

setsid sleep 100

「test1.sh」シェル スクリプトがすぐに終了しません

$ cat test2.sh
#!/bin/bash

setsid sleep 100 &

「test2.sh」シェルスクリプトはすぐに終了します。

誰か説明してくれませんか?どうもありがとう。

4

2 に答える 2

0

最初のスクリプトは終了するのを待ってsetsid sleep 100から戻ります(つまり、スリープが終了した後、ここでは100秒戻ります)、2番目のスクリプトはコマンドが終了するのを待たず&、コマンドをバックグラウンドにしてすぐに戻ります. 引用するにはman bash

If  a  command is terminated by the control operator &, the shell executes the
command in the background in a subshell. The shell does not wait for the command
to finish, and the return status is 0.

&また、は制御演算子であり、優先順位が高いことに注意してください。お役に立てれば!

于 2014-01-20T12:06:47.630 に答える