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
  • You are right about quoting, thank you. I don't want to swap the given directory with the top directory, I want to push the given directory on the top so that the current directory is now second, and the second directory is now third, and so forth. DIRSTACK is rather finicky about being set, which is why I used a separate array to do the manipulation. Commented Apr 4, 2020 at 23:29
  • Yes, I was only thinking about pd +1, sorry. In DIRSTACK you cannot splice entries in or out, or set DIRSTACK[0] (it will silently fail) Commented Apr 4, 2020 at 23:40
  • Still, you can get rid of the tempstack array: pd(){ local t=${DIRSTACK[$1]}; DIRSTACK=("" "${DIRSTACK[@]:0:$1}" "${DIRSTACK[@]:$1+1}"); cd "$t"; dirs; } Commented Apr 4, 2020 at 23:54