Last week I was working on an Eclipse project which requires me to create one executable .sh (shell script)
file. Here is a content of Crunchify.sh file.
#!/bin/bash echo ------------------------------- echo Starting up Crunchify Project echo ------------------------------- CLASSPATH=$CLASSPATH:"./lib":"." export CLASSPATH cd /crunchify/project java -jar Crunchify.jar
I was working on Windows environment so during deployment I copied all my project files to Linux dev box. While running I got this strange error.
[root@appshah scripts]# ./Crunchify.sh -bash: ./Crunchify.sh: /bin/bash^M: bad interpreter: No such file or directory
After scratching my head for almost 10 mins found an issue with file format. File wasn’t correctly created with UTF-8 and Unix format.
Now here is a simple solution:
Use dos2unix
Utility:
dos2unix includes utilities to convert text files with DOS or MAC line breaks to Unix line breaks and vice versa. It also includes conversion of UTF-16 to UTF-8.
Above solution works perfectly for Windows user but what if you are running your development on MAC OS X. Well, there is a simple trick for that too.
$ cat Crunchify.sh | col -b > Crunchify2.sh mv Crunchify2.sh Crunchify.sh
Where Crunchify.sh is the file that has the Control+M
characters at the end of the line, and Crunchify2.sh the new file you are creating!
NOTE:
Try using a different name for the target file. Hope this help. Enjoy and Happy coding.