source
显然,如果该脚本在当前目录中,我就不能编写脚本。例如,
# 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。
引用源手册页:
源文件名 [参数]
……
如果 filename 不包含斜杠,则使用 PATH 中的文件名来查找包含 file-name 的目录。
所以...source
正在尝试script.sh
在PATH
.
如果要在当前文件夹中获取文件,请使用
source ./script.sh
使用绝对路径 -- source /root/path/to/some/dir/script.sh
-- 应该对你进行排序。
This can happen when the file is in the wrong format. I FTP'd a Korn Shell script from Windows. I could edit it, but got "not found [No such file or directory]" when I tried to run it. It turned out it was in DOS format, which was indicated in the file name line when I edited it in vi. After I re-FTP'd it, making sure it was being transferred as ASCII, it ran fine.