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

Re: Nested quotes

On Tue, Nov 24, 2015 at 09:37:58AM +0000, Peter Stephenson wrote:
> On Tue, 24 Nov 2015 08:36:27 +0100
> Dominik Vogt <vogt@xxxxxxxxxxxxxxxxxx> wrote:
> > Maybe I'm just thick this morning, but how do you "nest" double
> > quotes here:
> > 
> >   $ FILE="foo bar"
> >   $ echo "$(readlink -f $FILE)"
> >   readlink: extra operand `bar'
> > 
> > Obviously $FILE needs to be quoted too.
> I'm guessing the difference between you and Simon is you have the
> SH_WORD_SPLIT option set for some sort of sh-compatibility.  You've now
> discovered why it's not set by default.
> You either to turn the option off again or provided explicit quoting of
> $FILE where it occurs as an argument to readlink.
> To wokr out how to quote it, you need to know that the fact the readlink
> command is in $(...) inside quotes can be ignored --- the contents of an
> $(...) expression are parsed step by step, so the only thing that will
> terminate it is that closing ")", which can't occur in a syntactically
> valid fashion for any other reason.  (That wasn't fully true until
> quite recently, but the details only involve odd cases like case
> statements where unpaired closing parentheses occur, so you can ignore
> this subtlety for simple expressions even with older versions of the
> shell.)
> So it's fine to do
>   echo "$(readlink -f "$FILE")"

Thanks for the explanation; I wasn't aware of this property of
$(...).  The reason why I have shwordsplit is really to be closer
to other shells when scripting, i.e. to force myself to quote


Dominik ^_^  ^_^


Dominik Vogt
IBM Germany

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