Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

7
  • I understand pushd and popd to work as you describe and that they're independent of command substitution - no confusion there! However, you answered by own problem by revealing $OLDPWD. I can do popd; rmdir $OLDPWD. That;s the answer to my problem - everything else just confirms what I thought. Command substitution appears to be a way to solve it but it isn't because of the subshell and you can't do command substitution without a subshell, So thanks for revealing OLDPWD - that's exactly what I need! Commented Aug 3, 2016 at 14:47
  • @starfry, rmdir $(popd) causes popd to run in a sub-shell which means it won't change the current directory, but even if it did not run in a subshell, the output of popd will not be the temporary directory, it will be a space separated list of directories not including that temp dir. Which is where I'm saying you're confused. Commented Aug 3, 2016 at 14:59
  • but I thought I had said that in my question: "popd doesn't return the popped directory (it returns the new, now current, directory) and also because it's performed in a subshell." Admittedly it returns a list, but the first in the list is the one I was referring to. Commented Aug 3, 2016 at 15:57
  • @starfry, OK sorry. Let's say I was the one confused by the title of the question and didn't read the rest carefully enough. Commented Aug 3, 2016 at 17:30
  • well your answer was still good and pointed me in the right direction. I never knew about that shell variable OLDPWD. I must remember to one day read man bash from end-to-end ! Commented Aug 3, 2016 at 19:50