3

I found some inconsistent behavior of $BASHPID as below:

# On Mac Yosemite
echo $BASH_VERSION ${BASH_VERSINFO[5]} $BASHPID
# => 3.2.57(1)-release x86_64-apple-darwin14

# On Ubuntu
echo $BASH_VERSION ${BASH_VERSINFO[5]} $BASHPID
# => 4.3.11(1)-release x86_64-pc-linux-gnu 29134

The $BASHPID is not present for Mac OSX, is it not safe to use it to write portable script?

1
  • 2
    The version on OS X is quite old and with high probability do not support this variable Commented May 14, 2015 at 20:00

1 Answer 1

4

The builtin variable $BASHPID was introduced in bash version 4.0.

See the file NEWS in the bash source code:

 397 -------------------------------------------------------------------------------
 398 This is a terse description of the new features added to bash-4.0 since
 399 the release of bash-3.2.  As always, the manual page (doc/bash.1) is
 400 the place to look for complete descriptions.
 401 
 402 1.  New Features in Bash
 403 
 ...
 410 c.  There is a new variable, $BASHPID, which always returns the process id of
 411     the current shell.
2
  • Notice this release is back in 2009, surprisingly Yosemite still ships version 3.*.
    – steveyang
    Commented May 14, 2015 at 20:44
  • 1
    @steveyang One possible explanation for why Apple continues to ship out-of-date software is here.
    – John1024
    Commented May 14, 2015 at 21:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .