$BASHPIDと$$は場合によって異なります。

$BASHPIDと$$は場合によって異なります。

「オレリーのBASHポケットガイド」を読んでいます。それは言う:

現在の Bash プロセスのプロセス ID。場合によっては$$と異なる場合があります。

上記の説明は$BASHPID変数を説明しています。

質問:どんな状況ですか?

ベストアンサー1

BASHPIDbash マンページの説明に例を示します。

   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.

以下は、変数の内容と$$サブシェルの外側の内容を印刷するサブシェルの例です。BASHPID

$ 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

おすすめ記事