[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Error when script uses CRLF line endings w/ if stmt

From: driscoll
Subject: Error when script uses CRLF line endings w/ if stmt
Date: Thu, 4 Feb 2010 14:49:27 -0600

Configuration Information [Automatically generated, do not change]:
Machine: i686
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='i686' 
-DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='i686-pc-linux-gnu' 
-DCONF_VENDOR='pc' -DLOCALEDIR='/usr/local/share/locale' -DPACKAGE='bash' 
-DSHELL -DHAVE_CONFIG_H   -I.  -I. -I./include -I./lib   -g -O2
uname output: Linux point.cs.wisc.edu 2.6.18-164.11.1.el5 #1 SMP Wed Jan 6 
13:26:31 EST 2010 i686 i686 i386 GNU/Linux
Machine Type: i686-pc-linux-gnu

Bash Version: 4.1
Patch Level: 0
Release Status: release

        Some of the time, using CRLF line endings cause syntax errors
        in Bash scripts ("unexpected end of file").

        This problem shows up on Bash 4.1 on Linux, Bash 3.2 on Linux,
        and Bash 3.2 on Cygwin (where I first noticed it).

        Create a file containing the following contents:
                if true; then
                    echo foo;
        (This seems to be robust to a few changes: putting 'then' on
        the next line; omitting the semicolon from the end of
        'echo foo'.)

        Verify that it works:
                $ ./bash ../test.sh  

        Convert the line endings to CRLF:
                $ unix2dos ../test.sh
                unix2dos: converting file ../test.sh to DOS format ...

        Verify that it fails:
                $ ./bash ../test.sh  
                ../test.sh: line 4: syntax error: unexpected end of file

        (Alternately, you can create it with CRLF, show that it
        fails, dos2unix it, and show it now works.)

reply via email to

[Prev in Thread] Current Thread [Next in Thread]