尽管在 PATH 中,但未找到可执行文件

Hac*_*chi 4 linux bash shell path

我的 $PATH 设置为很多目录,包括~/bin~/target/bin

我想执行里面的 script.sh~/target/bin但我收到错误bash: ~/bin/script.sh: No such file or directory

这让我很困惑,因为which找到了正确的目录 ~/target/bin 并且 ~/target/bin/script.sh 执行得很好。

bash 中是否有任何特殊设置可能导致这种错误的路径处理?

小智 6

您可以尝试运行hash -r以清除可执行缓存。

Bash 将可执行文件的位置保存在缓存中,因此如果您重新运行该命令,它就不必再次搜索整个路径。 有关hash命令的更多信息

  • 这有帮助;非常感谢您。你能解释一下这个可执行缓存是什么吗?我以前从未听说过 (2认同)
  • csh/tcsh 中的“rehash” (2认同)