pRAShANT
pRAShANT

Reputation: 523

Does $! mean something in shell scripting

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?

Upvotes: 10

Views: 10990

Answers (3)

Ranjithkumar T
Ranjithkumar T

Reputation: 1956

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

Upvotes: 0

anubhava
anubhava

Reputation: 785108

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

Upvotes: 11

user000001
user000001

Reputation: 33317

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

Upvotes: 8

Related Questions