3 ms·
I kind of feel like set -o errexit (i.e. set -e) provides enough unexpected semantics that explicit error handling makes more sense. One thing that often trips
by xelxebar 1y ago
I kind of feel like set -o errexit (i.e. set -e) provides enough unexpected semantics that explicit error handling makes more sense. One thing that often trips people up is this:
set -e
[ -f nonexistent ] && do_something
echo 'this line runs'
but
set -e
f(){ [ -f nonexistent ] && do_something; }
f
echo 'This line does not run'
modulo some version differences.
- chubot 1y agoYup, that is pitfall 8 here - https://oils.pub/release/latest/doc/error-handling.html#list-of-pitfalls https://oils.pub/release/latest/doc/error-handling.html#list... I think I got that from the Wooledge Wiki Explicit error handling seems fine in theory, and of course you can use that style with OSH if you want But in practice, set -e seems more common. For example, Alpine Linux abuild is a big production shell script, and they gradually switched to set -e (really, you're damned if you do, and damned if you don't, so that is a big reason YSH exists)