*banner
 

Software Development
FAQ
CVS
Previous section  |  This section  |  Next section
Previous question  |  This question  |  Next question

Cygwin CR/NL problems
Christopher Brooks, 9 Aug 2010
Last updated: 17 Nov 2010

After about 2009, Cygwin installs with line endings that are set up for Linux gurus that fail for most Windows users.

See Ptolemy II Cygwin installation instructions for details, which are partially reproduced below:

  • Set bash to ignore carriage returns '\r' The problem is that shell scripts such as $PTII/bin/vergil will fail:
    $ export PTII=c:/user/ptII
    $ $PTII/bin/vergil
    c:/user/ptII/bin/vergil: line 30: $'\r': command not found
    c:/user/ptII/bin/vergil: line 40: $'\r': command not found
    c:/user/ptII/bin/vergil: line 43: $'\r': command not found
    c:/user/ptII/bin/vergil: line 48: $'\r': command not found
    c:/user/ptII/bin/vergil: line 67: syntax error near unexpected token `$'in\r''
    ':/user/ptII/bin/vergil: line 67: `    case "`uname -s`" in
      

    Another possible solution is to create a ~/.bash_profile that contains

    export SHELLOPTS
    set -o igncr
    
    To find your home directory, start up Cygwin bash and type cd;pwd. Then use an editor like Wordpad. See also:

  • OLD Information below here

    When Cygwin is installed, you should be sure to select DOS for the Default Text File Type.
    If you do not, then when you check in files, there will be problems with the DOS CR/NL line endings.
    In particular, what will happen is that when you check in a file and then someone checks it out, it will have extra \r or ^M characters.

    The way to tell if this is a problem is to run the mount command under Cygwin bash and note whether the c: drive is mounted textmode or not. If the c: drive is mounted textmode, then your setup is ok:

    $ mount
    c:\cygwin\bin on /usr/bin type system (textmode)
    c:\cygwin\lib on /usr/lib type system (textmode)
    c:\cygwin on / type system (textmode)
    c: on /cygdrive/c type user (textmode,noumount)
    
    However, if c: is mounted binmode, then you have problems:
    $ mount
    c:\cygwin2\bin on /usr/bin type system (binmode)
    c:\cygwin2\lib on /usr/lib type system (binmode)
    c:\cygwin2 on / type system (binmode)
    c: on /cygdrive/c type user (binmode,noumount)
    

    The fastest solution is to reinstall Cygwin, see How do I edit pages in a group with the "CVS Authoring" option? and properly select DOS for the Default Text File Type.
    Another possible alternative is to use these mount commands:
    We have tried these commands but they have not quite worked for us

    mount -f -t -s c:\\cygwin\\lib /usr/lib
    mount -f -t -s c:\\cygwin\\bin /usr/bin
    mount -f -t -s c:\\cygwin /
    mount -f -t c: /cygdrive/c
    
    If you have a d: drive,you may need to do:
    mount -f -t d: /cygdrive/c
    
    When you are done, run mount, which should show all the mounts as textmode.

    The reason that this is a problem with CVS is that CVS handles end of line translation between Unix and Windows.
    If, under Cygwin, the directories are mounted binmode, then Cygwin CVS will not do the proper translations.
    For details, see How is the DOS/Unix CR/LF thing handled? in the Cygwin FAQ
    See also http://cygwin.com/cygwin-ug-net/using-textbinary.html

    To replicate the problem, install Cygwin with Unix line endings, check out a file using CVS, edit the file using wordpad and check in your changes. When you check out the file under Unix, it will have \r\n line endings.

    Note that there is some contention about whether DOS or Unix line endings are correct. The TinyOS community has required Cygwin to be set up with Unix line endings, which works great if your users are technically sophisticated. However, if your windows users do not have much exposure to Unix, then configuring Cygwin to use DOS line endings is more correct.

Previous section  |  This section  |  Next section
Previous question  |  This question  |  Next question
©2002-2018 Chess