In a related question somebody states that the directory stack of the pushd
command is emptied when your shell terminates. But how is the stack actually stored? I use fish instead of bash and the commands work the same way. I would assume pushd
(and popd
) works independently of the shell you're using. Or do both shells have their own implementation?
1 Answer
The directory stack is not stored anywhere permanent. Shell just keeps it in process memory, in an array DIRSTACK
(which has restrictions on user modification). It's not even strictly a stack -- bash and ksh allow you to rotate it left and right by specified counts, too.
In Bash, the dirs
command clears or shows the stack in various ways, popd
removes any specified dir, and pushd
adds a dir or rotates the stack to change to any of the dirs already stored.
The pushd stack is not "cleared" as such. Pushd is a shell built-in, not an external command (which would not be able to change the shell's own environment). Each shell retains its own pushd data, and when that shell process goes away, the contents are just discarded.