Is there any $! mean something in shell scripts

Does $ exist ! in a bash / shell script, if so, tell me what it is used for. And why is it empty when echo $! run on the command line?

+4
source share
3 answers

In addition to another answer, this is an echo

 echo $! 

It will be printed blank if you have not already executed any process in the background in the current shell. If you are running now:

 date & echo $! 

Then it will print something like (for example, the process identifier of the last executed background process):

 47833 
+6
source

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

+4
source

$! - Shows the last identifier of the process that started in the background.

0
source

Source: https://habr.com/ru/post/1499106/


All Articles