ngs
ngs copied to clipboard
$(seq 1000000 | head -2)
Right now NGS will throw an exception because the first process ended with signal (SIGPIPE). Rethink the behaviour and error detection design.
Interestingly enough, analogous bash also fails in the same manner:
$ bash -c 'set -eo pipefail; seq 1000000 | head -2; echo OK'; echo $?
1
2
141
Probably SIGPIPE should be excluded when considering which commands have failed
Same issue in Elvish - https://github.com/elves/elvish/issues/952
FWIW Oil has a run
builtin which is used to tweak exit codes. This comes up in a couple places:
-
grep
can return 0, 1, or 2. That's "found", "not found", or "error". - this SIGPIPE problem. For this we have
run --status-ok SIGPIPE printf ... | head
.
From:
https://old.reddit.com/r/bash/comments/mivbcm/the_set_o_pipefail_is_not_a_best_practice/gtefb4a/
FWIW Oil has a
run
builtin which is used to tweak exit codes. This comes up in a couple places:* `grep` can return 0, 1, or 2. That's "found", "not found", or "error".
What's the default behavior for grep exiting with 1?
--allow-status-01
is the related switch? How about other exit codes which I want to express "are OK"? Do I use --assign-status
and then check or --status-ok
also handles exit codes, not just signals (did not find non-SIGPIPE examples) ?
* this SIGPIPE problem. For this we have `run --status-ok SIGPIPE printf ... | head` .
From:
https://old.reddit.com/r/bash/comments/mivbcm/the_set_o_pipefail_is_not_a_best_practice/gtefb4a/
Yup, that's the flag for grep
. There's a long thread about it here where we went through almost all the names possible :)
https://oilshell.zulipchat.com/#narrow/stream/121540-oil-discuss/topic/status.20builtin.20proposal
And yes if you want more complicated logic, you use --assign-status
, and then use a normal shell case
statement on the var:
run --assign-status :st -- cc myfile.cc
case $st {
(0) echo zero ;;
(1) echo one ;;
}
Oil allows braces, but in shell that's just:
case $st in
(0) echo zero ;;
(1) echo one ;;
esac
I came up with an imperfect detection mechanism, thought my fellow shell designers might be interested: https://github.com/elves/elvish/issues/952#issuecomment-816277862
I came up with an imperfect detection mechanism, thought my fellow shell designers might be interested: elves/elvish#952 (comment)
Thanks! I'll take a look (I see there is a bit of discussion happened)
Note: elvish got this solved. Todo: take a look and most likely adopt the solution