是$!在shell脚本中意味着什么

时间:2023-01-27 21:43:50

Does $! exists in bash/shell script, if yes, please inform for what it is used for. And why it gives blank when echo $! is run on the command line?

是$!存在于bash / shell脚本中,如果是,请告知它的用途。为什么它在回声$时给出空白!在命令行上运行?

3 个解决方案

#1


8  

In addition to other answer, this echo

除了其他答案,这个回音

echo $!

Will print blank if you haven't yet run any process in background in current shell. If you now run:

如果您尚未在当前shell中的后台运行任何进程,则将打印为空白。如果您现在运行:

date &
echo $!

Then it will print something like (i.e. process id of last executed background process):

然后它将打印出类似的内容(即上次执行的后台进程的进程ID):

47833

#2


5  

$! is the PID of the last program your shell ran in the background

$!是shell在后台运行的最后一个程序的PID

#3


0  

$! - shows last process ID which has started in background.

$! - 显示已在后台启动的最后一个进程ID。

#1


8  

In addition to other answer, this echo

除了其他答案,这个回音

echo $!

Will print blank if you haven't yet run any process in background in current shell. If you now run:

如果您尚未在当前shell中的后台运行任何进程,则将打印为空白。如果您现在运行:

date &
echo $!

Then it will print something like (i.e. process id of last executed background process):

然后它将打印出类似的内容(即上次执行的后台进程的进程ID):

47833

#2


5  

$! is the PID of the last program your shell ran in the background

$!是shell在后台运行的最后一个程序的PID

#3


0  

$! - shows last process ID which has started in background.

$! - 显示已在后台启动的最后一个进程ID。