bug-bash@gnu.org

2013-12-15 Thread Martin Kealey

I wrote:
> Description:
> The value of $? after starting a backgrounded command is inconsistent:
> $? is unchanged after starting a sufficiently complex command, but
> after starting a simpler command it is set to 0.

> From: Chet Ramey
> Thanks for the report. The exit status of any asynchronous command is 0.
> I will fix this for bash-4.3-release.
>

On Sat, 14 Dec 2013, dethrop...@web.de wrote:
> I thought the value was only 0 if the fork/spawn was succesful.
> i.e. if it fails for lack of resources or something it's non zero.
>
> or have I miss understood it's [sic] significance?

I'm inclined to agree; there seems little point in arbitrarily always
setting it to 0, when it could be used to provide information -- either the
success-or-failure of the fork() (or spawn()), or simply retaining the
previous status.

While on the subject of exit status, any chance of being able to wait on a
list of processes (or "any"), and get back the exit status and pid of the
next one to finish? And to find out status of a stopped job? And to
distinguish between an exit status of 129 and SIGHUP?

(That lack had me rewriting a significant chunk of code in Perl when it was
otherwise nearly finished in Bash.)

I'm thinking of these additions:

 wait -o [JOB ...]

  wait for one child process out of the given list, or for any single child 
process if no list is given.

  sets $! to the pid of a child process which has terminated (or stopped), and 
sets $? in the normal manner pertaining to that process

  if no child process can be waited for, unsets $! and sets $? to 1 for ECHILD 
or 2 for EAGAIN

  if waiting for one-of-many but not "any" is unsupported, unsets $! and sets 
$? to 3

  (-o is implied if one or more JOBs are given)

 wait -e
 shopt -s exitstatus

  when a child process is terminated or stopped by a signal, set $? to zero 
minus the signal number (rather than 128 plus the signal number), so that the 
full 8-bit range of exit statuses are distinguishable

 wait -t

  implies -o

  report a child process which has stopped or terminated

  sets $? to indicate the signal which cause the process to stop or terminate

 wait -tt

  like -t, but only report on a child process which has stopped, not terminated
  sets $? to 3 if unsupported by the OS

Names for options are negotiable, but I chose to avoid '-s' because it's
rather ambiguous in this context: single? signal? status? stopped? Long
option names might also be nice.

Waiting for multiple processes (but not all) presents some challenges; Perl
implements this by waiting for all, and stashing the statuses until the
script actually waits for them.

-Martin



feature request: apply parameter expansions to array keys

2013-12-15 Thread Ken Irving
No bug here, but I naively expected the pattern substitution expansion
to work on array keys as well as values, e.g.:

$ declare -A h
$ h[foo]=x h[bar]=y
$ # show keys and values:
$ printf "\t<%s>\n" "${!h[@]}" "${h[@]}"




$ # try to pad keys and values:
$ printf "\t<%s>\n" "${!h[@]/#/}" "${h[@]/#/  }"
<>
<  y>
<  x>

I wanted to print out array keys with some padding, easily done in a loop,
but I wanted the padding applied to the separate strings generated using
the quoted [@] expansion.

The manpage documents the ${!name[@]} 'List of arrays keys' expansion
separately from the pattern substitution expansion, so it's all working
as documented, but I think the syntax could allow this.

I'm not running the latest bash: 

$ bash --version
GNU bash, version 4.2.37(1)-release (i486-pc-linux-gnu)

Ken



bug-bash@gnu.org

2013-12-15 Thread Chet Ramey
On 12/14/13, 2:08 PM, dethrop...@web.de wrote:
>I thought the value was only 0 if the fork/spawn was succesful.

Sure, of course.  (Posix does not document any other return value, btw.)

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