【发布时间】:2021-06-29 19:07:23
【问题描述】:
考虑以下文件夹结构:
$ tree ~/test_path
test_path
`-- sub_folder
`-- script.sh
1 directory, 1 file
假设您已通过以下方式将 test_path 添加到您的路径中
export PATH=$PATH:~/test_path
$ whereis sub_folder
sub_folder: /home/murtraja/test_path/sub_folder
现在如何通过调用 sub_folder/script.sh 来执行 script.sh?
$ sub_folder/script.sh
bash: sub_folder/script.sh: No such file or directory
编辑:我不想更改调用 sub_folder/script.sh,因为这是由另一个我无法(避免)更改的脚本调用的。
【问题讨论】:
-
必须在 PATH 中包含包含脚本的目录才能在不指定路径的情况下运行它。
-
是的,可以这样做,但我不想更改调用
sub_folder/script.sh,因为这是由另一个我无法更改的脚本调用的 -
将此添加到您的
~/.bashrc:function sub_folder/script.sh { (cd ~/test_path; command sub_folder/script.sh); };)
标签: bash shell ubuntu path environment-variables