pushd
并且popd
在处理多个目录时很方便。有时我想推送一个目录以便稍后处理,而不必立即转到该目录,这似乎pushd -n
正是
只存在一个小问题 —— 尝试这样做通常会导致出现No such file or directory
以下情况:
$ ls foo
Files I Want
$ pushd -n foo # I'll want to go there later
~ foo
$ cd bar # But I have other things to do first
$ # ... doing other things ...
$ # Done! Now, I want to go back to foo
$ popd # Fortunately I placed that on the dir stack earlier
~/bar/foo
$ ls
"Wait, this isn't where I wanted to end up"
有没有一种解决方法,可以将目录存储在堆栈中,而不必在我popd
稍后移动到该目录之前将我移动到该目录中,并且即使我在此期间移动到其他目录也可以让我这样做?
答案1
指定绝对路径:
pushd -n $PWD/foo
pd() { pushd -n "$(realpath "$1")"; }