Wednesday 22 February 2012

Command not found shell script

Problem: Every time I run my shell script "example.sh" it always gives me result "command not found". Though all the commands in script get executed, Still I get this message

Reason: The root cause for this problem is line ending characters represented different in Windows and Linux.

Solution: Convert the file format from Windows to Linux. You can use the command "dos2unix" that will 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)
 
# dos2unix example.sh

If you are a java developer and using ant to build your code. You can use below ant task to convert file format from dos to unix.
 

No comments:

Post a Comment