加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

linux – 无法在当前目录中获取脚本

发布时间:2020-12-14 02:22:07 所属栏目:Linux 来源:网络整理
导读:显然,如果脚本在当前目录中,我无法获取脚本.例如, # source some/dir/script.shOk 工作正常,但如果我和脚本在同一个目录中,则会出错: # cd some/dir# source script.sh-sh: source: script.sh: file not found 是什么赋予了?这是改变目录的唯一方法吗? 如
显然,如果脚本在当前目录中,我无法获取脚本.例如,
# 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.

所以……源代码试图在PATH中包含的文件夹中搜索你的script.sh.

如果要在当前文件夹中使用源文件

source ./script.sh

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读