无法在当前目录中提供脚本 [英] can't source script in a current directory

查看:93
本文介绍了无法在当前目录中提供脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,显然,如果该脚本位于当前目录中,则我不能source一个脚本.例如,

So apparently, I can't source a script if that script is in the current directory. For example,

# source some/dir/script.sh
Ok

可以正常工作,但是如果我与脚本位于同一目录中,则会出错:

works fine, but if I'm in the same dir as the script, it errors out:

# cd some/dir
# source script.sh
-sh: source: script.sh: file not found

有什么作用?这是更改目录的唯一方法吗?

What gives? Is the only way around this to change directory?

如果相关的话,我正在Angstrom Linux上使用bash v4.2.10.

I'm using bash v4.2.10 on Angstrom Linux if that's relevant.

推荐答案

引用源手册页:

源文件名[参数]

source filename [arguments]

....

如果filename不包含斜杠,则文件 PATH中的名称用于查找包含文件的目录- 名称.

If filename does not contain a slash, file names in PATH are used to find the directory containing file- name.

所以... source试图在PATH包含的文件夹中搜索您的script.sh.

So... source is trying to search your script.sh in the folders contained in PATH.

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

If you want to source a file in the current folder use

source ./script.sh

这篇关于无法在当前目录中提供脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆