Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

can't source script in a current directory

Tags:

linux

bash

sh

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?

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

like image 445
Nicu Stiurca Avatar asked Feb 15 '13 07:02

Nicu Stiurca


2 Answers

Quoting the source man page:

source filename [arguments]

....

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

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
like image 84
Davide Berra Avatar answered Sep 21 '22 00:09

Davide Berra


Use an absolute path -- source /root/path/to/some/dir/script.sh -- should sort you.

like image 36
hd1 Avatar answered Sep 20 '22 00:09

hd1