What does $$ or $ mean! in bash?

This is a simple question, but I did not find any information. What does $! mean $! or $$ in bash?

For example: ps -p $! or pstree $$ ?

-one
source share
2 answers

Actually, these variables were inherited by bash from the Bourne shell.

"$$" means the current PID.

"$!" this is the PID of the last program that your shell ran in the background (for example, "myprog &")

Here is a list of shell variables:

+6
source

$! is the process id of the last job running in the background.

$$ is the process id of the script itself.

(Both of these links are related to TDLP's Advanced Bash Scripting Guide.)

0
source

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


All Articles