bug-bash
[Top][All Lists]
Advanced

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

Re: behavior diff. btw. 3.0 and 3.1 (may be a bug)


From: Eric Blake
Subject: Re: behavior diff. btw. 3.0 and 3.1 (may be a bug)
Date: Thu, 23 Feb 2006 07:06:07 -0700
User-agent: Mozilla Thunderbird 1.0.2 (Windows/20050317)

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

According to vw@vonwolff.de on 1/23/2006 6:52 AM:
> 
> Description:
>       There is a behavior difference between bash 3.0 and 3.1. This results
>         in trouble installing oracle database software. in 3.0 `cmd` can
>         span over lines, in 3.1 not.
> 
> Repeat-By:
>       
> a=`echo 'a b c' | sed 's/ /\\
> /g' | grep 'b'`
> echo $a

Or shorter:

bash-3.0 $ echo `echo '\\
> a'`
\ a

bash-3.1.9 $ echo `echo '\\
> a'`
\a

Using 'set -xv' is useful here to seeing what bash is trying to do.  bash
3.0 invokes the subcommand "echo '\[newline]a'" (after IFS splitting, the
outer echo sees two parameters) while bash 3.1.9 invokes the subcommand
"echo '\a" (the outer echo sees only one parameter).

The difference here is the POSIX parsing rules
(http://www.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html).
  Section 2.3 token recognition states that in command substitution, "The
shell shall read sufficient input to determine the end of the unit to be
expanded (as explained in the cited sections). While processing the
characters, if instances of expansions or quoting are found nested within
the substitution, the shell shall recursively process them in the manner
specified for the construct that is found."  And in Section 2.6.3, inside
backticks, backslash is only a quoting character if it is followed by $,
`, or \.

In your example, there is a backslash followed by another backslash, so
the first \ is a quoting character per the rules of command substitution,
but it occurs inside single quotes, where it must be a literal character
per the rules of nested construct parsing.  I think that the strict
reading of POSIX is as follows - the first ` starts a command
substitution, which then recursively parses to the end of the construct.
During that search, backquote parsing does not recursively use single
quoting rules (although unquoted single quotes must appear in matched
pairs, or the results are undefined), but does see that the first \ quotes
the second (and not the second quoting a newline).  All the characters
parsed form the final token, which is "`echo '\\[newline]a'", but which
the command substitution sees as "echo '\[newline]a'.  So I think you did
find a regression - bash 3.0 is correct in preserving the newline between
the quoted backslash and remaining characters, while bash 3.1 (through
patchlevel 9) is incorrect in performing newline joining.

- --
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

iD8DBQFD/cFO84KuGfSFAYARAqLBAJ0Q57l+VEzUMy+RTp50KNcX3QjboACfWfP7
eJ4R7BRNhXl5TJAjCyvnFvA=
=Crns
-----END PGP SIGNATURE-----




reply via email to

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