Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Expansion/quoting quirks

> This one seems really strange to me.  Why is $(foo) different from `foo`
> in ksh?  I think I prefer zsh's behavior, even if it isn't compatible.
>     $ echo $(echo '\$x')
>     \$x
>     $ echo `echo '\$x'`
>     $x
>     $
> Look, ksh isn't even consistent about it!  Why should that $ cause a
> magically different behavior?
>     $ echo $(echo '\x')
>     \x
>     $ echo `echo '\x'`
>     \x
>     $

Here is the relevant part from the ksh93 manual:

   Command Substitution.
       The standard output from a command enclosed in parentheses
       preceded  by  a  dollar  sign  (  $() ) or a pair of grave
       accents (``) may be used as part or all of a word;  trail-
       ing new-lines are removed.  In the second (obsolete) form,
       the string between the quotes  is  processed  for  special
       quoting  characters  before  the  command is executed (see
       Quoting below).  The command substitution $(cat file)  can
       be replaced by the equivalent but faster $(<file).

                                                ...  Inside grave
       quote marks (``), \ quotes the characters \, `, and $.  If
       the  grave  quotes occur within double quotes, then \ also
       quotes the character ".

The baseline zsh implement this behaviour.  However when it is invoked as sh
or ksh, it sets the glob_subst option which.  But glob_subst is buggy in the
baseline, since the result of the expansion is not only globbed but also
expanded using parameter expansion.

E.g. foo='$foo' ; echo $foo

causes an infinite loop when glob_subst is set.



Messages sorted by: Reverse Date, Date, Thread, Author