bug-bash
[Top][All Lists]
Advanced

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

Re: $(case x in x)...


From: Eric Blake
Subject: Re: $(case x in x)...
Date: Wed, 04 Jan 2006 07:21:25 -0700
User-agent: Mozilla Thunderbird 1.0.2 (Windows/20050317)

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

According to Eric Blake on 12/28/2005 12:00 PM:
> 
> My results: bash 3.1, with or without patch 1, still has
> the bug.
> 
> $ k=$(case x in x) echo hi; esac)
> bash: syntax error near unexpected token `esac'

While we are complaining about command-substitution parsing bugs, I found
two others.

$ echo $(cat<<\eof
> '
> eof
> )
> # Whoa - why is bash still trying to continue the here-doc/$()?
> '
> eof
> )
bash: command substitution: line 4: syntax error near unexpected token `)'
bash: command substitution: line 4: `)'
'
$

Somehow, in a quoted here-doc nested inside an unquoted command
substitution, bash is trying to find pairs of ''.  At least I was able to
satisfy the parser, and get back to a normal prompt.


$ echo "$(cat<<\eof
> `
> eof
> )"
> # Whoa - why is bash still trying to continue the here-doc/$()?
> `
> eof
> )"
> # nope, still going
> [ctrl-c]
$

Somehow, a mistmatched ` inside the quoted here-doc embedded in a quoted
command substitution is completely throwing off the parser, and I cannot
figure out how to get back to a normal shell short of interrupting the
command altogether.

Of all the shells I have tested, ash is the only one that got these correct:

$ echo $(cat<<\eof
> '
> eof
> )
'
$ echo "$(cat<<\eof
> `
> eof
> )"
`
$

This becomes important when trying to use here-docs to type in perverse
directory names.  I have come across a situation where it is much easier
to surround a literal filename with arbitrary shell code than it is to
modify the filename to be properly quoted (creating a Windows shortcut
that can launch an arbitrary cygwin shell in an arbitrary directory, see
http://cygwin.com/ml/cygwin/2006-01/msg00133.html - Windows uses %L to
generate a literal filename inside arbitrary text).  But with bash, it is
impossible to use an arbitrary literal directory name, because of the bugs
present when ` or ) appear in the literal name.

- --
Life is short - so eat dessert first!

Eric Blake             ebb9@byu.net
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD4DBQFDu9nl84KuGfSFAYARAuqNAJ9NaS15HQjvu6mivYyK4rot+JnCLQCXbmUf
7A30dUcL/hd2zcz+aviByw==
=dBS3
-----END PGP SIGNATURE-----




reply via email to

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