bashmacos

How to get BASHPID in Bash version 3


On MacOS we have bash version 3.2 installed by default. Is there a way to get BASHPID for subshell or is it just impossible?

For what I gather online this is the case:

current_pid="$$"

(
  [[ "$current_pid" != "$$" ]] && exit 1
  [[ "$BASHPID" == "$$" ]] && exit 1
)

so the BASHPID is the same unless you're in a subshell. So with Bash version 3 is there a way to get the PID of the subshell?


Solution

  • BASHPID was introduced in bash-4.0-alpha, so I would expect no.