I tried following these instructions to go back to the previous directory, but that results in "-bash cd: OLDPWD not set".
我尝试按照这些说明返回到前一个目录,但结果是“-bash CD:OLDPWD未设置”。
How could I do what I want?
我怎么能做我想做的事呢?
Thank you.
谢谢。
更多回答
cd -
can't be the first command in the shell, you would have needed to cd somewherelse
first so you have a thing to cd
back to
Cd-不能是外壳中的第一个命令,您需要先在其他位置执行cd操作,这样才能找到需要cd的内容
优秀答案推荐
I had the same problem. Add an alias for exit to write pwd to a file and then read it on the next start:
我也有同样的问题。为Exit添加别名以将pwd写入文件,然后在下一次启动时读取该文件:
alias exit='pwd > ~/.lwd && exit;'
test -f ~/.lwd && export OLDPWD='head -1 ~/.lwd'
This solved the problem for me
这解决了我的问题
When you open a new terminal the PWD is not set as the terminal opens in the /home/ directory of the user. If you change the current directory and then use this command then you will not face this problem. Actually, this is not even a problem this is how the terminal should actually behave.
当您打开一个新终端时,当终端在用户的/home/目录中打开时,不会设置PWD。如果更改当前目录,然后使用此命令,则不会遇到此问题。事实上,这甚至不是问题,这是终端实际应该如何运行的问题。
What actually helped in my case was using
在我的案例中真正有帮助的是使用
cd /
instead of
而不是
cd -
yeah.. it works for me too.
是的..对我也有效。
you should use
cd /
instead of
cd -
believe me it will fix the error
你应该用cd/而不是cd-相信我它会修复这个错误的
更多回答
This is the right answer. This is the default behaviour of bash.
这是正确的答案。这是bash的默认行为。
我是一名优秀的程序员,十分优秀!