Friday, March 30, 2007

Shell script execution - command not found, syntax error near unexpected token

When we edit shell script in Windows machine, and ftp it to Linux for execution, sometimes we hit the following error:

command not foundh” line xxx
command not foundne” line xxx: syntax error near unexpected token `

This is due to the newline characters used on both systems. We need to replace all occurances of "\r\n" with "\n".

In vi, do the following:

// Change from (DOS) to just (Unix):
:set fileformat=unix

// change back to Carriage Return + Line Feed for DOS
:set fileformat=dos

// writing for apple computers:
:set fileformat=mac

// remove multiple (repeated) Carriage Returns using search and replace