It's kind of easy question but I didn't find any information. What does mean $!
or $$
in bash?
For example: ps -p $!
or pstree $$
?
The $$ variable is the PID (Process IDentifier) of the currently running shell. This can be useful for creating temporary files, such as /tmp/my-script. $$ which is useful if many instances of the script could be run at the same time, and they all need their own temporary files.
$$ is the pid (process id) of the shell interpreter running your script. It's different for each process running on a system at the moment, but over time the pid wraps around, and after you exit there will be another process with same pid eventually.As long as you're running, the pid is unique to you.
The echo command is used to display a line of text that is passed in as an argument. This is a bash command that is mostly used in shell scripts to output status to the screen or to a file.
$$ gives the process id of the currently executing process whereas $! Shows the process id of the process that recently went into the background.
Actually, these variables were inherited by bash from the Bourne shell.
$$
means current PID.
$!
is the PID of the last program your shell ran in the background (e.g. myprog &
)
Here is a list of shell variables:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With