I was working on a script to set up a project-specific environment. I created a script to set up the directory stack as suggested in the first comment to this question. Console output provided evidence that the stack was being created as designed, but as the script completed, the stack did not exist when I was returned to the console.
I suspect that this is a design feature to allow the script writer an independent environment, and that this touches on a question of broader scope concerning how the environment is handled inside and outside of a script. What is going on and where can I learn more?
cd
(or changing the current environment in other ways) in a script that is run in a separate child process can't affect the parent shell's environment, I'm closing this as a duplicate of https://unix.stackexchange.com/questions/27139/script-to-change-current-directory-cd-pwd – Kusalananda Feb 04 '21 at 17:49