Reputation: 4050
I'm trying to write a bash script in CentOS that tests the various echo escape sequences. However, when I run the program
./test.sh a
I keep getting this error message:
bad interpretation: no such file or directory
Here is the script:
#! /bin/bash
# Test echo escape sequences
input=$1
case $input in
a ) echo -e "\a" testing \a;;
b ) echo -e "\b" testing \b;;
c ) echo -e "\c" testing \c;;
* ) echo Incorrect input
exit 1;;
esac
Where did I go wrong?
EDIT: I'm running CentOS Minimal guest in VirtualBox on a Windows XP host
EDIT 2:
#! bin/bash
was in my script, not
#! /bin/bash
When I changed it to
#! /bin/bash
and run the program ./test.sh a, it just prints "a"
Upvotes: 2
Views: 3592
Reputation: 2339
[EDIT] Based on the original post, this is usually caused by DOS LINE ENDINGS.
The CR in the CR/LF DOS line ending is being seen by the interpreter as part of the shell that should be used to execute the script.
So, it tries to load /bin/bash(CR) which does not exist, hence "bad interpreter" is displayed.
One easy way to correct this is to copy the contents of the script to the clipboard and then:
cat > test.sh (PASTE CLIPBOARD) (PRESS ENTER) (PRESS CTRL-D)
This will strip out any incorrect line endings (there are other ways to do it but this is a pretty easy / straight-forward solution.
Once the "bad interpreter" issue was resolved, another syntax error in the script is the use of "\a" when you probably intend '\a'.
[EDIT] I think I realize what you mean now. Try this instead:
echo -e '\a' testing '\\'a
Upvotes: 4
Reputation: 23858
Did you make the script executable with something like
chmod 755 test.sh
Added
I wonder if part of the problem is the escape sequence you are using as they could mean \a=cursor up \b=cursor down \c=cursor forward.
Or also interpreted as \a=SOH Start of Heading \b=STX Start of Text or \c=ETX End of Text
Upvotes: 2