Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

This question already has an answer here:

While going through:

info coreutils 'dd invocation'

I came across:

dd if=/dev/zero of=/dev/null count=10MB & pid=$!

What is $! used for?

share|improve this question

marked as duplicate by Mikel, manatwork, slm, Renan, Anthon Oct 23 '13 at 16:57

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

Are you using bash? –  slm Oct 22 '13 at 20:02
@slm how am I supposed to find out? –  Bleeding Fingers Oct 22 '13 at 20:05
You could try this command: echo $SHELL –  slm Oct 22 '13 at 20:07
@slm yes, it's bash. /bin/bash. –  Bleeding Fingers Oct 22 '13 at 20:08
$! is (at least) POSIX so not specific to bash. I'd assume it's universal to sh. –  goldilocks Oct 23 '13 at 15:52

2 Answers 2

up vote 13 down vote accepted

If you're talking about Bash they're in the "Special Parameters" section of the Bash man page.

!      Expands to the process ID of the most recently executed background 
       (asynchronous) command.


$ sleep 10 &
[1] 22257

$ echo $!

Your command

So with this command:

$ dd if=/dev/zero of=/dev/null count=10MB & pid=$!

The dd command is backgrounded, and the resulting process ID ($!) is stored in a variable pid for use there after.


share|improve this answer

$! is used to get the PID(process identifier) of the most recent background command.

There is also !$:

!$ is used to get last argument for the last executed command.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.