Velvet Star Monitor

Standout celebrity highlights with iconic style.

general

Trouble editing ~/.bash_profile: -bash: $'\r': command not found

Writer Sophia Terry

I installed CygWin on Windows 7. Using Notepad, I edited my ~/.bash_profile file to add on to the PATH variable …

PATH="${PATH}:/cygdrive/c/apache-ant-1.8.2/bin"

Now, when I SSH in to my Windows machine, I get this error …

-bash: $'\r': command not found
-bash: $'\r': command not found
-bash: $'\r': command not found
-bash: $'\r': command not found
-bash: $'\r': command not found
-bash: /home/dev/.bash_profile: line 39: syntax error: unexpected end of file

and my PATH is not set. Anyone know how I can correct this?

1

3 Answers

As mentioned already, Windows uses \n\r as line separator. Now that you've got the \rs in your .bash_profile, however, you can use the utility dos2unix to remove them.

1

Probably notepad has added some $'\r', i. e. CR characters - as it is usual under Windows to have CRLF as line terminator.

The solution would be to use another editor which is capable to keep the line endings as they are, e. g. vim for Windows, or Notepad2.

3

Depending on the environment you are using, you might be stuck with scripts containing CRLF, i.e. when using Visual SourceSafe, Perforce for Windows etc. to store your files. However, bash has a universal way to get around this problem:

export SHELLOPTS
set -o igncr

If you put this at the start of your .bash_profile or other startup script you may be using, you are out of trouble, as the CRLF sequences before the first command in your startup script do not hurt.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy