I’m working on a modification of this approach to automatically saving and restoring bash’s directory stack state when using pushd
and popd
.
For some reason, my code to restore the saved state isn’t working — I’m calling pushd
on the right entries, and it says it’s pushing those onto the stack, but afterwards, dirs -v
is unchanged!
I have some directories, one per line, in a file, and I’m using this to recreate the stack:
tac $BASH_DIR_STACK_FILE | sort | uniq | while read -r dir
do
echo $dir
pushd -n "$dir" > /dev/null
done
When I run that, it works as expected, and claims to be pushing each of the directories. But afterwards, when I do dirs -v
, there’s no change to the stack!
Using pushd
manually for the same directories works as expected.
I also tried the declare
approach with $DIRSTACK
from this post but that doesn’t work either.
Why isn’t my directory stack getting updated via pushd
inside that loop?