bug-bash
[Top][All Lists]
Advanced

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

Characters aren't being properly escaped/evaluated in a Bash


From: garrett . w . cooper
Subject: Characters aren't being properly escaped/evaluated in a Bash
Date: Wed, 9 May 2007 16:55:08 -0700

Configuration Information [Automatically generated, do not change]:
Machine: x86_64
OS: linux-gnu
Compiler: /usr/intel/bin/gcc
Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='x86_64' 
-DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='x86_64-unknown-linux-gnu' 
-DCONF_VENDOR='unknown' -DLOCALEDIR='/usr/intel/00r1.1/share/locale' 
-DPACKAGE='bash' -DSHELL -DHAVE_CONFIG_H  -I.  -I. -I./include -I./lib   -O2 
-fPIC -L/usr/intel/pkgs/readline/5.0-64/lib 
-I/usr/intel/pkgs/readline/5.0-64/include 
-I/nfs/pdx/disks/comp.build_system.1/bash/3.0/em64t_linux26/bash-3.0/include 
-I/nfs/pdx/disks/comp.build_system.1/bash/3.0/em64t_linux26/bash-3.0 
-L/usr/intel/pkgs/ncurses/5.4/lib -I/usr/intel/pkgs/ncurses/5.4/include
uname output: Linux filc9194 2.6.5-7.276.PTF.196309.1-smp #1 SMP Mon Jul 24 
10:45:31 UTC 2006 x86_64 x86_64 x86_64 GNU/Linux
Machine Type: x86_64-unknown-linux-gnu

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

Description:

        Summary:
                Characters aren't being properly escaped/evaluated in a Bash

        Full Description:

                I'm trying to take a series of lines in a file like so (ignore 
1.-3. characters -- they're just there for
                visual breaking):

                1. This is a file with multiple
                2. fields spread across multiple
                3. lines.

                and group it up into line by line groups, and analyze with
                "for" in bash. The problem is that if I did this out of the box
                like the following, it 'flattens' the list:

                Example:
                        for j in `cat $i`; do
                                echo $j
                        done

                Output:
                        This
                        is
                        a
                        file
                        [...]

                According to the Advanced Bash Scripting Manual, the following
                should be -- and is -- possible:

                Example:
                        for j in "This is a file with multiple" "fields spread 
across multiple" "lines."; do
                                echo $j
                        done

                Output:
                        This is a file with multiple
                        fields spread across multiple
                        lines.

                Ok, cool. Now, in order to do this I chose Perl as my method of 
escaping the lines
                (couldn't get GNU sed to work as expected and I don't know awk 
/ tcl), as follows:

                for j in `$PERL -e "chomp(\$lines=qx{cat $i}); 
foreach(split(\"\\n\", \$lines)) { printf(\"\'%s\'\", \$_); }"`; do
                        echo $j
                done

                Output:

                filc9194[202]% ./scripts/mk_batch.sh vfe1 falcon2
                syntax error at -e line 1, near "chomp(="
                Execution of -e aborted due to compilation errors.
                No valid lines in 
/nfs/fm/disks/fm_vt_n19029/users/gwcooper/vibe_regress/scripts/../archived/esperanto_list.txt
 (all commented and/or empty)

                Interestingly enough, the script fails. This shouldn't be done 
because I properly escaped the dollar signs in the
                double quotes, thus the Perl variables shouldn't be interpreted 
and evaluated by Bash, but instead be left alone
                for Perl to do its bidding.

                I know this solution isn't the most ideal one, and although I 
might receive workarounds which use sed, the fact is
                that this is a bug with Bash. This behavior fails not only in 
older versions of Bash (2.0, the system Bash), but also
                the version that Intel compiles for its Suse machines (3.0.0), 
as well as the version available for Cygwin (3.1.7).

                gwcooper@ecwm0gwcooper ~
                $ ./test.sh 
                syntax error at -e line 1, near "chomp(="
                Execution of -e aborted due to compilation errors.

                gwcooper@ecwm0gwcooper ~
                $ bash --version
                GNU bash, version 3.2.17(15)-release (i686-pc-cygwin)
                Copyright (C) 2005 Free Software Foundation, Inc.

Repeat-By:
        Run the following lines (replace $i appropriately with a file of your 
choosing):

        #!/bin/bash

        PERL=`which PERL`

        i=/pick/a/file/with/lines/in/it

        for j in `$PERL -e "chomp(\$lines=qx{cat $i}); foreach(split(\"\\n\", 
\$lines)) { printf(\"\'%s\'\", \$_); }"`; do
                echo $j
        done

Fix:
        The problem lies in the parser somewhere, but I can't look through the 
code (at least not now) because I have my hands full with other things. If I do 
find the issue and can submit a fix, I will.




reply via email to

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