Le 14/02/2012 05:35, Aaron Davies a écrit :
what's the best way to abort a pipeline partway through?
e.g. in a simple case,
$ ls foo
ls: foo: No such file or directory
$ cat foo|wc -l
cat: foo: No such file or directory
0
$
i'd prefer it stopped after the "cat foo" failed
(i'm sure this is a common request, but i've tried googling for solutions and
haven't found anything)
how about using set -o pipefail ?
from man ksh :
The exit status of a pipeline is the exit status of the last command
unless the pipefail option is enabled.
pipefail
A pipeline will not complete until all compo‐
nents of the pipeline have completed, and the
return value will be the value of the last non-
zero command to fail or zero if no command has
failed.
w/o pipefail :
$ ls foo | wc -l; echo rc=$?
ls: cannot access foo: No such file or directory
0
rc=0
w/ pipefail :
v2$ ls foo | wc -l; echo rc=$?
ls: cannot access foo: No such file or directory
0
rc=2
Regards,
Cyrille Lefevre
--
mailto:[email protected]
_______________________________________________
ast-users mailing list
[email protected]
https://mailman.research.att.com/mailman/listinfo/ast-users