Does $! mean something in shell scripting

2020-04-05 06:26发布

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?

3条回答
太酷不给撩
2楼-- · 2020-04-05 06:37

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

查看更多
ゆ 、 Hurt°
3楼-- · 2020-04-05 06:55

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

查看更多
狗以群分
4楼-- · 2020-04-05 07:01

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:

date &
echo $!

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

47833
查看更多
登录 后发表回答