Monday, June 13, 2011

Cygwin : "bash: $'\r': command not found"

When we copy bash scripts, edit them and then try to run these on the Cygwin, many a times we get the error :-
"bash: $'\r': command not found".

I don't know the exact reason for this, but it seems the bash can't read the file properly, so we need to use the dos2unix.exe command in the cygwin to convert the script to readable format. This solves the problem.

Syntax :- dos2unix.exe scriptname .

Then run the script. It should run fine.

2 comments :

  1. The reason is the line return character is different between linux and windows. dos2unix changes linux return character to windows format

    ReplyDelete
    Replies
    1. i did use notepad and vi editors in windows to edit the files.

      Tony,
      I started using bash scripts again few weeks back. This was after a gap of 1.5 years. But, I have also started learning VBA programming for Excel. I hope you remember that a lot of scripts that we ran were meant to modify csv files or check them for analysis. It seems with VBA programming, one can do the same thing quite easily. Check it out.

      Delete