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: Lenga, Yair
Subject: RE: Possible bug with BASH V4: The "$!"
Date: Thu, 11 Apr 2013 16:15:45 +0000

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).
+ 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.
+ Could not find any change log on my system (probably a problem with RH). Not 
sure if it's documented.

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.

This is very confusing, and probably conflict with POSIX standard which 
indicate that "$!" apply to "CURRENT" shell.

Thanks
Yair

-----Original Message-----
From: Chet Ramey [mailto:address@hidden 
Sent: Thursday, April 11, 2013 10:14 AM
To: Lenga, Yair [ICG-MKTS]
Cc: Dan Douglas; address@hidden; address@hidden
Subject: Re: Possible bug with BASH V4: The "$!"

On 4/11/13 9:24 AM, Dan Douglas wrote:
> On Thursday, April 11, 2013 01:05:43 PM Lenga, Yair wrote:
>> With BASH 3.0, the backgrounded task could access the PID of the 
>> parent using "$$", and the PID Of itself as "$!".
>>
>> With BASH 4.0, the script fail, the "$!" is not available to the 
>> child process.
>>
>> Is it possible to add back the functionality to allow the child 
>> process to somehow retrieve it's OWN PID.  I assume that the behavior 
>> of  "$$" cannot be modified at this time.
> 
> BASHPID was introduced in Bash 4. I would guess that prior to that, 
> the behavior of $! was either a nonstandard extension or unintentional 
> bug. Check the changelog.

According to the change log, I made this change in late November 2006 as the 
result of a shell discussion on the austin-group list.  BASHPID came in to 
replace it shortly after.

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]