我正在编写自己的 unix 脚本,因此我想为 Bash 添加一个新目录。我在 .bash_profile 中添加了这样的内容。
PATH="~/Documents:${PATH}"
export PATH
Run Code Online (Sandbox Code Playgroud)
在我的〜/ Documents中,有一个名为test的文件,其内容是
#!/usr/bin/env python3.5
print("hahahhah")
Run Code Online (Sandbox Code Playgroud)
我也用过
chmod 755 test
Run Code Online (Sandbox Code Playgroud)
使其可执行。
但我无法直接在终端中调用它。./test照常工作。什么地方出了错?
当我更改为
PATH="$HOME/Documents:${PATH}"
export PATH
Run Code Online (Sandbox Code Playgroud)
什么都没发生。
FDSM_lhn@9-53:~/Documents$ test
FDSM_lhn@9-53:~/Documents$ ./test
hahahhah
Run Code Online (Sandbox Code Playgroud)
解决方案:根本原因是我有一个与默认命令同名的命令,所以它无论如何都不起作用!改个名字就够了!