Error message 'source: not found' when running a script
/bin/sh
is not bash
. To execute your script with bash
, write #!/bin/bash
as the first line in your script.
The error source: not found
is not dropped, because /etc/profile
is not found. It's dropped, because source
is not found. source
is a Bash built-in function, and you don't execute the script with bash
. So it's clear why it is not found. Change the #!
line in the script, and it will work.
1. How can I be sure that the script is executed by Bash, even if
#!/bin/sh
is specified (apparently, it does not guarantee it)?
To be sure that a script written for sh
shell (as in your case - see What is difference between #!/bin/sh and #!/bin/bash?) is executed by Bash, just run the following command:
bash script_name
Thus, you will not get that error anymore.
2. Why would it say that these two sources cannot be found when they are unmistakably there?
It doesn't say that those sourced files are not there. It says that the source
command is not found. This is normal, because since you start your script with #!/bin/sh
line, your script will run using sh
and not bash
as you may think. Why is it normal? Because source
command is a Bash builtin, but not a sh
builtin. To source a file in sh
, you should use .
(dot). Example:
. /etc/profile
. ~/.profile
Another way is to change the shebang line to #!/bin/bash
as chaos said in his answer.
Some shells support .
instead of source
. So you can try something like this
. filename
instead of
source filename
Hope it works