On the surface it means: The current bash PID, but the various shell environments to understand thoroughly.
Official explanation:
Bashpid
Expands to the process ID of the current bash process. This differs from
$$ under certain circumstances, such as subshells that does not require bash
To is re-initialized.
Outputs the PID of the current bash process. This is different in the following case, such as not getting to bash's child shell, will be reinitialized.
Example 1:
[[email protected] ~]$ ps-ef |grep bash |grep-v grep
Andy 30245 30244 0 Jul17 pts/0 00:00:00-bash
[Email protected] ~]$ echo $$
30245
Note: $$ represents the process ID of the login shell (a shell that is directly logged in by an Andy user ssh connection)
[Email protected] ~]$
Example 2:
[Email protected] std]# ps-ef |grep Bash
Root 4422 4421 0 Jul23 pts/0 00:00:02-bash
Root 13791 4422 0 22:14 pts/0 00:00:00 grep--color=auto Bash
Andy 30245 30244 0 Jul17 pts/0 00:00:00-bash
[Email protected] std]# echo $$
4422
Note: $$ is the PID that logged into the interactive shell (I was Andy Login, then sudo su-to root)
Example 3:
[Email protected] std]# echo $$
4422
[email protected] std]# cat test.sh
#/bin/bash
echo "Fei Jiao hu Shi Shell ' S process pid:$$"
[Email protected] std]# sh test.sh
Fei Jiao hu Shi Shell ' S process pid:13858
Note: This is a non-interactive shell, and the shell,$$ that is executed by the script is this PID
Example 4:
[Email protected] ~]$ echo $$
30245
[Email protected] ~]$ echo "abc" | {echo "abc"; Echo $$;}
Abc
30245
[Email protected] ~]$
Note: The Subshell in the pipeline, although it is a child shell environment, but does not get the-bash process, so the parent process is still bashid. (This is a bit of a detour, look at the official explanation of the English language to slowly understand it.) )
This article is from the "learning communication, the first job ops" blog, please be sure to keep this source http://cuidehua.blog.51cto.com/5449828/1831910
A detailed description of Shell $$