[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: pushd/popd

On Mon 12 Nov 2018 at 08:40:15 (-0500), Greg Wooledge wrote:
> 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.

Yes, quite a few of my bin/ scripts are like that. But in the aside,
I was really talking about scripts that are contained in OP's shell
functions where, if you pushd but then crash out for whatever reason
without doing the matching popd, you get left in a different directory
from the one you started in. Perhaps s/whenever/when/ and qualifications.


Reply to: