所有bash历史记录在包含空格的目录上没有此类文件或目录错误

Jac*_*ack 5 bash .bash-profile

我一直在尝试实现博客文章" 重新访问所有bash历史记录 "中描述的功能.基本上,脚本允许您执行的操作是永久保留所有bash历史记录并保持多个会话.

有人在Github上很容易地访问所有代码.

但是每当我使用带空格的目录时:

cd ~/Desktop/
mkdir "dir with spaces"
cd dir\ with\ spaces/
Run Code Online (Sandbox Code Playgroud)

我下次登录时会收到如下错误:

-bash: pushd: /Users/jack/Desktop/dir: No such file or directory
-bash: pushd: with: No such file or directory
-bash: pushd: spaces: No such file or directory
Run Code Online (Sandbox Code Playgroud)

我理解的唯一参考似乎没有导致问题:

# Now change to the new dir and add to the top of the stack
pushd "${the_new_dir}" > /dev/null
Run Code Online (Sandbox Code Playgroud)

我希望一些bash脚本专家可以指出代码中的错误,以便我可以修补它.

小智 4

这就是罪魁祸首:

for x in `hd 20` `pwd`; do cd_func $x ; done
Run Code Online (Sandbox Code Playgroud)

用。。。来代替:

( hd 20; pwd ) | while read x; do cd_func "$x"; done
Run Code Online (Sandbox Code Playgroud)

在 github 存储库中发出拉取请求。