I am trying to run my shell script from command line lets say;
my script looks like this:
#!bin/bash
echo hello
When try to run this source ./abcd.sh I get this error.
"' is not a typo you can run the following command to lookup the package that contains the binary:
command-not-found
: command not found
hello
"
Never seen this before something wrong with having a empty line before "echo hello" ? I was wondering if anyone else encountered something like this.
needs to be
or wherever bash is installed (you can locate this by doing
whereis bash
).Your program should work fine when invoked using bash, i.e.,
bash ./abcd.sh
, but when executed directly./abcd.sh
then the hashbang line does matter because that is how the interpreter is located for the script contained in the executable file.Try
echo 'hello'
, within quotes. It looks like there is a newline between theecho
command andhello
and it is trying to run 'hello' as a command.The hashbang line should be
#!/bin/bash
, but messing that up won't matter as it will interpret any line that starts with a hash as a comment.Along with the first line of your script being a comment, it sounds like your file has DOS line endings, and the carriage return is being treated as the command that isn't found. The error message sounds like something provided by a custom
command_not_found_handle
function (which I believe Ubuntu defines).Make sure your file does not have a BOM I had the same problem when editing a script under Windows with Notepad++. make sure to convert to "UTF-8 witout BOM".
Run script with debug option to see which line actually is failing:
Note: in this case the Shebang line will be treated as a comment, so if the rest of your script is correct, it will execute correctly: