# source some/dir/script.sh Ok
工作正常,但如果我和脚本在同一个目录中,则会出错:
# cd some/dir # source script.sh -sh: source: script.sh: file not found
是什么赋予了?这是改变目录的唯一方法吗?
如果相关,我在Angstrom Linux上使用bash v4.2.10.
source filename [arguments] …. If filename does not contain a slash,file names in PATH are used to find the directory containing file- name.
source filename [arguments]
….
If filename does not contain a slash,file names in PATH are used to find the directory containing file- name.
所以……源代码试图在PATH中包含的文件夹中搜索你的script.sh.
如果要在当前文件夹中使用源文件
source ./script.sh