3 ms·
The subshell syntax is great for: ( cd some_directory do_a_thing_here ) ... instead of all the pushd popd nonsense, and so much easier to follow. Y
by ben509 8y ago
The subshell syntax is great for:
( cd some_directory
do_a_thing_here )
... instead of all the pushd popd nonsense, and so much easier to follow.
You can also do this:
( set -e
bail_from_this
if_anything_fails ) < redirect || echo 'Something went wrong here, carrying on...'
And that won't set -e in your outer shell. You can also set -v to see what's being run just for those commands.
As far as writing functions without braces, I don't. It doesn't do anything useful, it's magical and weird to bash n00bs, and when you have to add a command you'll wind up adding the braces then.
The reason bourne shells have that is because the shell's raison d'etre is composing processes, so it makes sense that compound statements are simply processes themselves. (Maybe process is the wrong term here...) To expose that in the syntax, though, is just being overly clever, and it's more obvious now that people find it confusing.