'\r': command not found - .bashrc / .bash_profile [duplicate] '\r': command not found - .bashrc / .bash_profile [duplicate] bash bash

'\r': command not found - .bashrc / .bash_profile [duplicate]


When all else fails in Cygwin...

Try running the dos2unix command on the file in question.

It might help when you see error messages like this:

-bash: '\r': command not found

Windows style newline characters can cause issues in Cygwin.

The dos2unix command modifies newline characters so they are Unix / Cygwin compatible.

CAUTION: the dos2unix command modifies files in place, so take precaution if necessary.

If you need to keep the original file, you should back it up first.

Note for Mac users: The dos2unix command does not exist on Mac OS X.

Check out this answer for a variety of solutions using different tools.


There is also a unix2dos command that does the reverse:

It modifies Unix newline characters so they're compatible with Windows tools.

If you open a file with Notepad and all the lines run together, try unix2dos filename.


For those who don't have dos2unix installed (and don't want to install it):

Remove trailing \r character that causes this error:

sed -i 's/\r$//' filename


Explanation:

Option -i is for in-place editing, we delete the trailing \r directly in the input file. Thus be careful to type the pattern correctly.


For WINDOWS (shell) users with Notepad++ (checked with v6.8.3) you can correct the specific file using the option- Edit-> EOL conversion-> Unix/OSX format

And save your file again.

Edit: still works in v7.5.1 (Aug 29 2017)