Skip to contentSkip to conversation

errexit and pipelines

DISCUSSION Marcin Owsiany 2 participants 2 messages Oct 7, 2008 – Oct 8, 2008

lore
Share & tools
lore
#0 lore raw

Hello,

I have recently found a problem with _bash_ that is described in the following thread in bash-bug mailing list:
http://groups.google.com/group/gnu.bash.bug/browse_thread/thread/e37f5c7ddcc55eeb/57474f8d2f8efa59

In short, it's about the fact that the following lines make a "set -e" script abort:
true | false
for a in 1; do false; done
but the following does not:
true | for a in 1; do false; done

I thought that this inconsistency was a bug in bash, but as you can find out in the thread, it is the first type of statements that behaves incorrectly, according to SUS.

Dash's manpage defines 'errexit' sematics differently: more like I would like it to work. It also works consistently in the above examples.

Since I like dash behavior more (makes it easier to write reliable scripts), I'm considering switching my program (cruft) to dash. But before I do it, can someone please confirm that what is written in the manpage and how dash behaves right now is indeed the intended behaviour, and will not in forseeable future be changed to match bash's behaviour?

regards,

Signature · 5 lines
Marcin Owsiany <[email protected]>              http://marcin.owsiany.pl/
GnuPG: 1024D/60F41216  FE67 DA2D 0ACA FC5E 3F75  D6F6 3A0D 8AA0 60F4 1216
 
"Every program in development at MIT expands until it can read mail."
                                                              -- Unknown
#1 lore raw
Quoted 4 lines · Marcin Owsiany

I thought that this inconsistency was a bug in bash, but as you can find out in the thread, it is the first type of statements that behaves incorrectly, according to SUS.

I disagree with Chet on that. My assessment is that POSIX/SUS is ambiguous on this. It is true that only simple commands can lead to the shell exiting. However, it also explicitly excludes pipelines starting with !. This can be construed as indicating that simple commands that are a part of a pipeline not preceded with ! can cause an exit.

Of course dash's current interpretation only includes the last component of the pipeline, when not preceded by !.

Quoted 5 lines

Since I like dash behavior more (makes it easier to write reliable scripts), I'm considering switching my program (cruft) to dash. But before I do it, can someone please confirm that what is written in the manpage and how dash behaves right now is indeed the intended behaviour, and will not in forseeable future be changed to match bash's behaviour?

I make no guarantees on this as SUS is subject to revision. However, I also have no plans to change this until such SUS clarifies this which probably won't occur for eons.

Cheers,

Signature · 4 lines
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt