bug-bash
[Top][All Lists]
Advanced

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

Re: bug: incorrect variable values when reading from file with 0d0a as n


From: Pierre Gaston
Subject: Re: bug: incorrect variable values when reading from file with 0d0a as newlines
Date: Tue, 17 Dec 2013 16:59:07 +0200

On Tue, Dec 17, 2013 at 3:18 PM, Sergey Skripnick
<address@hidden>wrote:

>
> Configuration Information [Automatically generated, do not change]:
> Machine: x86_64
> OS: linux-gnu
> Compiler: gcc
> Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='x86_64'
> -DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='x86_64-pc-linux-gnu'
> -DCONF_VENDOR='pc' -DLOCALEDIR='/usr/share/locale' -DPACKAGE='bash'
> -DSHELL -DHAVE_CONFIG_H   -I.  -I../bash -I../bash/include -I../bash/lib
>  -D_FORTIFY_SOURCE=2 -g -O2 -fstack-protector --param=ssp-buffer-size=4
> -Wformat -Werror=format-security -Wall
> uname output: Linux sskripnick-pc 3.11.0-14-generic #21-Ubuntu SMP Tue Nov
> 12 17:04:55 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
> Machine Type: x86_64-pc-linux-gnu
>
> Bash Version: 4.2
> Patch Level: 45
> Release Status: release
>
> Description:
>     When executed script (by `source' or by dot syntax) which have 0d0a
> characters as a newlines, readed variables have incorrect values. As you
> can see below, 0d character is included, but there is no 0d character
> between the quotes.
>
> Repeat-By:
>     Here the script for reproduce (dos2unix required)
>
> ---------------------------------------
> cat > data<<EOF
> VAR1="ok" # unused
> VAR="ok"
> VAR3="ok" # unused
> EOF
>
> cp data data-unix
> mv data data-dos
> unix2dos data-dos
>
> . data-dos
> echo $VAR | hexdump -C
> [ $VAR = "ok" ] && echo "eq" || echo "ne"
>
> . data-unix
> echo $VAR | hexdump -C
> [ $VAR = "ok" ] && echo "eq" || echo "ne"
>
> ---------------------------------------
>
> The output is:
> unix2dos: converting file data-dos to DOS format ...
> 00000000  6f 6b 0d 0a                                       |ok..|
> 00000004
> ne
> 00000000  6f 6b 0a                                          |ok.|
> 00000003
> eq
>

bash only recognize \n as a line ending.
\r is just a normal character as far as bash is concerned, so it rightly
finds that "ok\r" is not the same as "ok"

Btw you quote the wrong things, you should do:

[ "$VAR" = ok ]

so that the expansion is not split and pathname generation doesn't occur


reply via email to

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