3 ms·
Fun fact, in bash you lose the exit codes of process subs. It doesn't even wait() on those processes in many cases. So there is no way to abort a bash script
by chubot 5y ago
Fun fact, in bash you lose the exit codes of process subs. It doesn't even wait() on those processes in many cases.
So there is no way to abort a bash script if something like <(sort nonexistent) fails.
OSH lets you opt into stricter behavior:
$ osh -c
set -e
shopt -s oil:basic
diff <(sort left) <(sort nonexistent)
echo "should not get here"'
'
sort: cannot read: nonexistent: No such file or directory
diff <(sort left) <(sort nonexistent)
^~
[ -c flag ]:1: fatal: Exiting with status 2 (command in PID 29359)
In contrast, bash will just keep going and ignore failure.
You can also get all the exit codes with @_process_sub_status, which is analogous to PIPESTATUS.
(I should probably write a blog post about this: http://www.oilshell.org/blog/ http://www.oilshell.org/blog/)
- andreyv 5y ago> So there is no way to abort a bash script if something like <(sort nonexistent) fails. The process ID of the last executed background command in Bash is available as $!. cat <(sort nonexistent) wait $! || echo fail gives sort: cannot read: nonexistent: No such file or directory fail
- mkdirp 5y ago> The process ID of the last executed background command in Bash is available as $!. After a quick search it doesn't seem like this is an option for anything but the last executed background process. So if you have the typical `diff <(left) <(right)`, there is no easy way to get the pid of `<(left)`. I suppose you could output the pid to a file, and use it from there, though I haven't tested if that would work.