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”
[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