Every time I run a script using bash scriptname.sh
from the command line in Debian, I get Command Not found
and then the result of the script. So the script works but there is always a Command Not Found
statement printed on screen.
I am running the script from the /var
folder.
Here is the script:
#!/bin/bash
echo Hello World
I run it by typing the following:
bash testscript.sh
UPDATE - the problem appears to the blank lines. Each blank line is resulting in a command not found. Why would this occur?
use
dos2unix
on your script file.Make sure your first line is:
Enter your path to bash if it is not
/bin/bash
Try running:
That wil convert line endings, etc from Windows to unix format. i.e. it strips \r (CR) from line endings to change them from
\r\n (CR+LF)
to\n (LF)
.More details about the
dos2unix
command (man page)Another way to tell if your file is in dos/Win format:
The output will look something like this:
This will output the entire file text with
<CR>
displayed for each\r
character in the file.Problems with running scripts may also be connected to bad formatting of multi-line commands, for example if you have a whitespace character after line-breaking "\". E.g. this:
(please note the extra space after "\") will cause problems, but when you remove that space, it will run perfectly fine.
You may want to update you .bashrc and .bash_profile files with aliases to recognize the command you are entering.
.bashrc and .bash_profile files are hidden files probably located on your C: drive where you save your program files.
for executing that you must provide full path of that for example
On Bash for Windows I've tried incorrectly to run
without ./ at the beginning and got the same error.
For people with Windows background the correct form looks redundant: