bash: cd: 没有那个文件或目录
bash: cd: No such file or directory
我正在编写一个 bash 函数来跳转到我上次编辑的文件夹。
在我的示例中,最后编辑的文件夹标题为 'daniel'.
bash 函数看起来不错。
>>:~$ echo $(ls -d -1dt -- */ | head -n 1)
daniel/
而且我可以手动cd进入目录。
>>:~$ cd daniel
>>:~/daniel$
但是我不能使用bash函数来cd到目录中。
>>:~$ cd $(ls -d -1dt -- */ | head -n 1)
bash: cd: daniel/: No such file or directory
原来有人将 alias ls=ls --color
添加到此服务器的 bashrc 中。一旦别名被删除,我的功能就可以工作。 – 丹尼尔·谭
当您输入不存在的路径时,通常会抛出此错误。参见 -bash: cd: Desktop: No such file or directory。
但是 $(ls -d -1dt -- */ | head -n 1) 在输出中没有错误。因此,原因一定是当时 sh 和 bash 的不同用法。
就我而言,当我使用 bash 访问文件夹时,我有一个 docker 容器出现该错误。容器坏了,因为我在 docker-compose up
之后强行关闭了它,但没有用。在那之后,在现有的容器上,我只能使用 sh,而不是 bash。我发现这个是因为 OCI runtime exec failed: exec failed: container_linux.go:348: starting container process caused "exec: "bash": executable file not found in $PATH": unknown。我猜 bash 比 sh 晚加载,并且在容器启动时出现早期错误,只有 sh 被加载。
这很合适,因为您在 sh 中,从 >> 可以看出。使用 sh,一切都会按预期工作。但是这个表达式被 bash 解决了。可能出于某种原因未加载。
在docker中,使用docker-compose,我也有类似的错误说sh: 1: cd: can't cd to /root/MYPROJECT
。这可以通过使用
在服务中安装所需的卷来解决
services:
host:
volumes:
- ~/MYPROJECT:/MYPROJECT # ~/path/on/host:/path/on/container
参见 Mount a volume in docker-compose. How is it done? and or the official docs。
我正在编写一个 bash 函数来跳转到我上次编辑的文件夹。 在我的示例中,最后编辑的文件夹标题为 'daniel'.
bash 函数看起来不错。
>>:~$ echo $(ls -d -1dt -- */ | head -n 1)
daniel/
而且我可以手动cd进入目录。
>>:~$ cd daniel
>>:~/daniel$
但是我不能使用bash函数来cd到目录中。
>>:~$ cd $(ls -d -1dt -- */ | head -n 1)
bash: cd: daniel/: No such file or directory
原来有人将 alias ls=ls --color
添加到此服务器的 bashrc 中。一旦别名被删除,我的功能就可以工作。 – 丹尼尔·谭
当您输入不存在的路径时,通常会抛出此错误。参见 -bash: cd: Desktop: No such file or directory。
但是 $(ls -d -1dt -- */ | head -n 1) 在输出中没有错误。因此,原因一定是当时 sh 和 bash 的不同用法。
就我而言,当我使用 bash 访问文件夹时,我有一个 docker 容器出现该错误。容器坏了,因为我在 docker-compose up
之后强行关闭了它,但没有用。在那之后,在现有的容器上,我只能使用 sh,而不是 bash。我发现这个是因为 OCI runtime exec failed: exec failed: container_linux.go:348: starting container process caused "exec: "bash": executable file not found in $PATH": unknown。我猜 bash 比 sh 晚加载,并且在容器启动时出现早期错误,只有 sh 被加载。
这很合适,因为您在 sh 中,从 >> 可以看出。使用 sh,一切都会按预期工作。但是这个表达式被 bash 解决了。可能出于某种原因未加载。
在docker中,使用docker-compose,我也有类似的错误说sh: 1: cd: can't cd to /root/MYPROJECT
。这可以通过使用
services:
host:
volumes:
- ~/MYPROJECT:/MYPROJECT # ~/path/on/host:/path/on/container
参见 Mount a volume in docker-compose. How is it done? and