On Sat, Nov 10, 2018 at 11:58:53PM -0600, David Wright wrote: > BTW whenever I change directory in scripts, I make sure that I'm in a > subshell by using ( and ), which guarantees that I get back to the > same directory however the script finishes.
Depends on the script. For scripts that change directory more than once (e.g. a software building script that runs "make" in several directories, one by one), I concur. That is sound advice. For a script that only changes directory once and then does everything from that directory (e.g. a wrapper), a subshell may be the exact opposite of what's wanted. In such cases, you would simply do "cd /some/where || exit" at the top of the script.