wait -n ignores invalid pids when valid pids are listed
Given a background process that has exited before the script got to wait -n: function foo() { return 1; } foo & FOO_PID=$! function bar() { sleep 1; } bar & BAR_PID=$! sleep 0.1 # should exit with 127 since FOO_PID is non-existent now wait -n $FOO_PID $BAR_PID Then wait -n will wait on BAR_PID to exit, despite the fact that FOO_PID is invalid. (Tested with 5.0.17.) Shouldn't it immediately exit with 127, as the docs suggest, since one id specifies a non-existent process? The way it currently works makes it hard to make a script that waits for one of a set of background processes to exit (ie. that fails if one of a set of background processes fails), since any error that happens before the script reaches the wait will simply be ignored.
Re: wait -n ignores invalid pids when valid pids are listed (solved!)
Am Dienstag, 27. April 2021, 11:45:44 CEST schrieb Robert Elz: > Date:Tue, 27 Apr 2021 05:57:40 + > From: "Beer, Mathis" > Message-ID: <3024777.xmhlYjkYgV@ka-nl-mbeer> > > | Given a background process that has exited before the script got to wait > | -n: > | > | function foo() { return 1; } > | foo & FOO_PID=$! > | > | function bar() { sleep 1; } > | bar & BAR_PID=$! > | > | sleep 0.1 > | # should exit with 127 since FOO_PID is non-existent now > | wait -n $FOO_PID $BAR_PID > > That's not the way it works, pid's "exist" for these purposes until > waited upon (just as they do in the process table for processes and > the wait() sys call). > > The exit status should be 1, as that's the exit status of foo. > > | Then wait -n will wait on BAR_PID to exit, despite the fact that FOO_PID > | is > | invalid. (Tested with 5.0.17.) > > A second wait -n (in bash) generates a diagnostic about the pid that > no longer exists (the NetBSD sh which has the same options doesn't do that) > but waits for anything valid. > > | The way it currently works makes it hard to make a script that waits for > | one of a set of background processes to exit > > Not if you code it properly. Use -p to help. It all just works. > > | (ie. that fails if one of a set of > | background processes fails), since any error that happens before the > | script > | reaches the wait will simply be ignored. > > No, it won't. > > kre Ah sorry, my first reply got lost cause I didn't do "reply to list" correctly. Yes, wait -n does the right thing. I hadn't realized at the time that the behavior in an interactive shell and a script was different, and all my tests were done in an interactive shell. All is good!
[PATCH] Add missing docs for 'set +o', 'set -o'
Add documentation for 'set -o', 'set +o' syntax to 'help set', 'info'. 'set -o'/'set +o' matches the POSIX behavior, but Bash's own documentation should also mention it. Phrasing is copied from the manpage, which already mentions it. --- builtins/set.def | 4 doc/bashref.texi | 5 + 2 files changed, 9 insertions(+) diff --git a/builtins/set.def b/builtins/set.def index 44f17691..b922ca97 100644 --- a/builtins/set.def +++ b/builtins/set.def @@ -114,6 +114,10 @@ Options: vi use a vi-style line editing interface #endif /* READLINE */ xtrace same as -x + If -o is supplied with no option-name, the values of the + current options are printed. If +o is supplied with no + option-name, a series of set commands to recreate the current + option settings is displayed on the standard output. -p Turned on whenever the real and effective user ids do not match. Disables processing of the $ENV file and importing of shell functions. Turning this option off causes the effective uid and diff --git a/doc/bashref.texi b/doc/bashref.texi index b0dc2fad..99c2875e 100644 --- a/doc/bashref.texi +++ b/doc/bashref.texi @@ -5401,6 +5401,11 @@ This also affects the editing interface used for @code{read -e}. Same as @code{-x}. @end table +If @code{-o} is supplied with no @var{option-name}, the values of the +current options are printed. If @code{+o} is supplied with no +@var{option-name}, a series of @code{set} commands to recreate the current +option settings is displayed on the standard output. + @item -p Turn on privileged mode. In this mode, the @env{$BASH_ENV} and @env{$ENV} files are not
Re: [PATCH] Add missing docs for 'set +o', 'set -o'
On Tue, Jul 18, 2023, at 20:58:50 CEST, Lawrence Velázquez wrote: > Presumably the synopses in all locations should also use this: > > -o [option-name] > +o [option-name] > > -- > vq Far as I can tell, they all already have it. It's just at the very bottom of the 'set' option list, whereas the '+o'/'-o' docs are below the '-o' part.