I'm trying to understand if there are any benefits of using:
pushd my_dir
make all # ... or something else
popd
vs
(
cd my_dir
make all # ... or something else
)
or is it merely a preference thing?
I guess the latter notation can have issues like you may need to set -e
(and other flags again), but it still carries out the exit code of its last command, and looks better in terms of syntax.
cd
is a standard command,pushd
andpopd
arebash
things, so they would not be portable unless you provided them as functions in ash
script.sh
things, whichbash
happens to implement. They should work in a vast majority of standard shells (with the possible exception of CSH style shells).pushd
/popd
) are not mentioned in POSIX at all.