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*

3
  • The problem with this, and what I was trying to solve, is that you cannot rmdir the current directory which is where you'd be when doing this. You need to effect the popd before doing the rmdir but you need to know what to remove and popd does not tell you that. I, like you, thought dirs -l -1 was the answer but have since discovered that the answer is actually to use $OLDPWD. Commented Aug 4, 2016 at 9:36
  • @starfry I believe that the shortest answer is to use: popd && rmdir ~-. Commented Aug 4, 2016 at 10:48
  • @starfry You could actually remove the current directory, no problem, provided it is empty (without forcing the erase). You could even call rmdir "$PWD" all right. Also, the current directory should be the one created by mktmp -d (if pushd $(mktemp -d) was executed beforehand) and to which pushd moves the pwd. So, yes, after pushd and before popd, the directory created is stored in $(dirs -1), I fail to see any problem. Commented Aug 4, 2016 at 10:51