I was going through some trouble to do some proper "pushd/popd cleanup" in my bash script. That is: if I did pushd
a few times, I wanted to make sure to do the same number of popd
before exit
.
However, I noticed that the pushd/popd stack doesn't seem to be global.
Suppose I have this script called example-pushd-twice.sh
in my homedir:
pushd /etc
pushd /tmp
And I do this from the shell from within my homedir: (resulting output in blockquotes)
dirs
~
./example-pushd-twice.sh
/etc ~
/tmp /etc ~
I now expected to still be in /tmp
and still having a dir stack with 3 dirs, however:
dirs
~
Is this correct behavior? Can I trust a shell script to invoke its own pushd/popd stack, so I don't have to care about cleaning up afterwards?