bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Possible bug with BASH V4: The "$!"


From: Chet Ramey
Subject: Re: Possible bug with BASH V4: The "$!"
Date: Thu, 11 Apr 2013 14:02:41 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:17.0) Gecko/20130307 Thunderbird/17.0.4

On 4/11/13 12:15 PM, Lenga, Yair wrote:
> Dan, Chet: Many thanks for the info about BASHPID.
> 
>  I've checked BASHPID on RH6, and it looks OK. Few comments related to making 
> the change visible, and POSIX compliance.
> 
> + The 'set' command, does not print the BASHPID, this make it very hard to 
> find it (unless you read every line in the BASH info file !).
>    It will be very helpful to include  BASHPID there (if set).

It does, but BASHPID is one of the special shell variables that springs
into existence only when it's referenced.  Run the following script; it
should display two lines of output:

sleep 1&
echo $BASHPID
set | grep ^BASHP

> + The man page list BASH_VERSION, etc., but no indication of BASHPID. It's 
> probably a good idea to put a note next to '$!' about BASHPID.

It's in there, and has been since bash-4.0.

> + Could not find any change log on my system (probably a problem with RH). 
> Not sure if it's documented.

That depends on your distribution.  There is a summary changelog (CHANGES),
a file listing new features (NEWS), and a detailed change log
(CWRU/changelog) in the FSF bash distribution.

> Also, I have a question about POSIX mode (and POSIX compliance).
> The POSIX says  '$!' is "most recent background command executed from the 
> current shell".
> 
> So in :
> 
> ( echo "$!") &
> ( echo "$!") &
> 
> According to POSIX, both calls should print "" (nothing). As the background 
> command does not come from the "current" shell.
> 
> With BASH4, The first call will print "" (nothing), second call will print 
> the PID of the first call.

The bash behavior is correct.  The Posix requirement that (...) subshells
create a `subshell environment', which is an exact copy of the parent
shell's state with a couple of minor exceptions, trumps the text you
quoted.

http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_12

for the exact reference.

Chet
-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU    address@hidden    http://cnswww.cns.cwru.edu/~chet/



reply via email to

[Prev in Thread] Current Thread [Next in Thread]