Ich lese „BASH Pocket Guide of Oreilly“.
Da stand:
Die Prozess-ID des aktuellen Bash-Prozesses.
In einigen Fällen kann diese von $$ abweichen.
Obige Erklärung , erklärte $BASHPID
Variable.
Frage: welche Fälle?
Akzeptierte Antwort:
Ein Beispiel finden Sie in der BASHPID
Beschreibung der Bash-Manpage:
BASHPID
Expands to the process id of the current bash process. This
differs from $$ under certain circumstances, such as subshells
that do not require bash to be re-initialized.
Hier ist ein Beispiel einer Subshell, die den Inhalt der Variablen zusammen mit $$
ausgibt und den Inhalt von BASHPID
außerhalb der Unterschale.
$ echo $(echo $BASHPID $$) $$ $BASHPID
25680 16920 16920 16920
# | | | |
# | | | -- $BASHPID outside of the subshell
# | | -- $$ outside of the subshell
# | -- $$ inside of the subshell
# -- $BASHPID inside of the subshell