bash script error: source: not found
Your second attempt using the absolute path should be the correct method.
Possible causes of your bug:
- The file doesn't exist.
- The file exists, but for some reason you can't read it (eg permissions or some filesystem error.
- You have an
alias
which is overriding the builtinsource
(fix withunalias source
) - You have a function which is overriding
source
(fix withunset -f source
) - You are somehow not using
bash
(although your bang line would suggest you are).source
is not POSIX. Usingsource
ondash
does not work, only.
works. - My test with
source
withbash
in POSIX mode worked, though maybe this is due to my version or compilation flags. Maybe this is different for you and you are in POSIX mode.
1 and 5 give errors like the one you posted.
You are probably logging in with a user that runs a shell other than bash. Suppose you log in with user X and X runs sh
or another shell, not bash, and with user X you run source myscript.sh
, then you should get the given error.
I was stack with similar problem when running stuff from rpm.spec file.
I fixed the problem by providing explicit path to the script.
So, instead of
source myfile
I had to to run
source ./myfile
I am not sure what was the exact reason for that but it looks like myfile was searched for on $PATH and in $CWD. I guess that is up to some configuration in shell.