gpt4 book ai didi

cd - results in "-bash: cd: OLDPWD not set"(Cd-结果为“-bash:cd:OLDPWD Not Set”)

转载 作者:bug小助手 更新时间:2023-10-24 23:19:23 25 4
gpt4 key购买 nike



I tried following these instructions to go back to the previous directory, but that results in "-bash cd: OLDPWD not set".

我尝试按照这些说明返回到前一个目录,但结果是“-bash CD:OLDPWD未设置”。



enter image description here



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的默认行为。

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com