While going through:
info coreutils 'dd invocation'
I came across:
dd if=/dev/zero of=/dev/null count=10MB & pid=$!
What is $! used for?
While going through:
info coreutils 'dd invocation'
I came across:
dd if=/dev/zero of=/dev/null count=10MB & pid=$!
What is $! used for?
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 $!
22257
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.
$! 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.