When I use popd alone it removes a directory from the stack and takes me to that directory. However, if I do cd $(popd) then no directory is removed from the stack.Since the process is simply forked and the result is put in place of the shell expansion, why isn't a directory taken off of the stack?
Why doesn't shell expansion on popd remove a directory from stack?
bash;shell;command substitution;pushd
The command substitution $() runs the command in a subshell. A subshell starts out as an identical copy of the main shell, but from that point on the main shell and the subshell live their own life.The shell process creates a pipe and forks.The child runs popd with its output connected to the pipe, then exits.The parent reads the data from the pipe and substitutes it into the command line.Since popd runs in the child process, its effect is limited to the child process. The directory is taken off the stack off the child's stack. Nothing happens to the stack in the parent.  Nearly identical; the differences are not relevant here.  