Re: [bash-bug] parsing error with heredoc and command substitution

2010-07-15 Thread Dr. Werner Fink
On Tue, Jul 13, 2010 at 01:51:31PM -0400, Alex Khesin wrote:
 Configuration Information:
 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   -g -O2 -Wall
 uname output: Linux alexk 2.6.32-gg173-generic #gg173 SMP Wed Jun 23
 05:24:15 UTC 2010 x86_64 GNU/Linux
 Machine Type: x86_64-pc-linux-gnu
 Bash Version: 4.1
 Patch Level: 5
 Release Status: release
 
 Description:
 
 The following script used to work in bash 3.2 but does not work with
 bash 4.x (I tried 4.0, 4.1.5, and 4.1.7)
 
 --
 #!/bin/bash
 
 a=$(/bin/cat  EOF | wc -l
 a
 b
 EOF
 )
 -
 
 /tmp/bug.sh: line 3: unexpected EOF while looking for matching `)'
 /tmp/bug.sh: line 8: syntax error: unexpected end of file
 
 The following works correctly (changed /bin/cat to cat):
 
 --
 #!/bin/bash
 
 a=$(cat  EOF | wc -l
 a
 b
 EOF
 )
 -
 
 and so does this (removed | wc -l):
 
 --
 #!/bin/bash
 
 a=$(/bin/cat  EOF
 a
 b
 EOF
 )
 -

Hmmm ... I would expect that

a=$((/bin/cat|wc -l) EOF
a
b
EOF
)

is more correct.

Werner

-- 
  Having a smoking section in a restaurant is like having
  a peeing section in a swimming pool. -- Edward Burr



Re: [bash-bug] parsing error with heredoc and command substitution

2010-07-15 Thread Andreas Schwab
Dr. Werner Fink wer...@suse.de writes:

 a=$((/bin/cat|wc -l) EOF
 a
 b
 EOF
 )

Useless subshell.

a=$({ /bin/cat | wc -l; } EOF
a
b
EOF
)

Andreas.

-- 
Andreas Schwab, sch...@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
And now for something completely different.



Re: [bash-bug] parsing error with heredoc and command substitution

2010-07-15 Thread Bernd Eggink

Am 15.07.2010 10:35, schrieb Andreas Schwab:

Dr. Werner Finkwer...@suse.de  writes:


a=$((/bin/cat|wc -l)EOF
a
b
EOF
)


Useless subshell.

a=$({ /bin/cat | wc -l; }EOF
a
b
EOF
)


...and useless cat:

a=$(wc -l EOF
a
b
EOF
)

Nevertheless, IMHO the OP's version should work. It works in ksh, for 
example.


Bernd

--
Bernd Eggink
http://sudrala.de