10

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。

4

3 回答 3

18

引用源手册页:

源文件名 [参数]

……

如果 filename 不包含斜杠,则使用 PATH 中的文件名来查找包含 file-name 的目录。

所以...source正在尝试script.shPATH.

如果要在当前文件夹中获取文件,请使用

source ./script.sh
于 2013-02-15T08:25:10.180 回答
1

使用绝对路径 -- source /root/path/to/some/dir/script.sh-- 应该对你进行排序。

于 2013-02-15T07:22:38.387 回答
0

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.

于 2019-08-21T15:20:18.250 回答