error with ' in command substitution

2007-10-30 Thread Scott Moser

Configuration Information [Automatically generated, do not change]:
Machine: i486
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='i486' 
-DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='i486-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   -g -O2 -Wall
uname output: Linux brickies 2.6.20-16-generic #2 SMP Sun Sep 23 19:50:39 UTC 
2007 i686 GNU/Linux
Machine Type: i486-pc-linux-gnu

Bash Version: 3.2
Patch Level: 13
Release Status: release

Description:
#= test.sh =
x=$(cat <<"EOF"
bad' syntax
EOF
)
#=== end test.sh ===

$ bash test.sh 
test.sh: line 2: unexpected EOF while looking for matching `''

test.sh: line 6: syntax error: unexpected end of file

Above, bash errors on the single ' in "bad'".

The above syntax works in on my version of dash (0.5.3-5ubuntu2) and the
version of busybox ash that I tested (1.1.3).

Using the backtick operator works on my version of bash, and a version 
2.05b.0 that I tested.  backtick does not work on 3.1.17 (sles 10)


I actually see the same behavior as this version of bash on ksh from AIX
5.3.0.0.  There, ksh works with `` bug fails with $().

So, I'm not 100% certain what the "correct" behavior is, but it
certainly seems like this should work.

Repeat-By:
printf "%s\n%s\n%s\n%s\n" \
   'x=$(cat <<"EOF"' "bad' syntax" 'EOF' ')' > test.sh
bash test.sh

printf "%s\n%s\n%s\n%s\n" \
   'x=`cat <<"EOF"' "bad' syntax" 'EOF' '`' > test.sh





Re: error with ' in command substitution

2007-10-30 Thread Matthew Woehlke

Scott Moser wrote:

Description:
#= test.sh =
x=$(cat <<"EOF"
bad' syntax
EOF
)
#=== end test.sh ===
[snip]

So, I'm not 100% certain what the "correct" behavior is, but it
certainly seems like this should work.


Given that:

cat << EOF
bad' syntax
EOF

...is correct syntax, IMO the same in command substitution should also 
be legal. In fact, this strikes me as a definite bug, because there does 
not seem to be a way to produce an unmatched single quote in a heredoc 
inside $() command substitution (nor using `` depending on your bash 
version, I guess).


FWIW, kate recognizes this as legitimate syntax (i.e. correctly "sees" 
the heredoc inside the substitution).


--
Matthew






Re: error with ' in command substitution

2007-10-30 Thread Eric Blake
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

According to Scott Moser on 10/30/2007 7:12 AM:
> #= test.sh =
> x=$(cat <<"EOF"
> bad' syntax
> EOF
> )

>
> So, I'm not 100% certain what the "correct" behavior is, but it
> certainly seems like this should work.

POSIX requires this to work when inside $(), but leaves it unspecified
when inside ``.  Yes, all released versions of bash are buggy when it
comes to 100% compliance to the POSIX rules for $() parsing (and more
annoyingly, with different bugs as you move from 3.1 to 3.2).

- --
Don't work too hard, make some time for fun as well!

Eric Blake [EMAIL PROTECTED]
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.5 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFHJ9Mh84KuGfSFAYARAppMAKCWFzg82nmRlT7We25GyH0q/egI0wCZASdj
gw94rDf1y2VM5e7JmkwqiJU=
=GwLt
-END PGP SIGNATURE-