From: Dominik Vogt <vogt@linux.vnet.ibm.com>
To: zsh-users@zsh.org
Subject: Re: Nested quotes
Date: Tue, 24 Nov 2015 10:51:04 +0100 [thread overview]
Message-ID: <20151124095104.GA29881@linux.vnet.ibm.com> (raw)
In-Reply-To: <20151124093758.2834203f@pwslap01u.europe.root.pri>
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@linux.vnet.ibm.com> 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
properly.
Ciao
Dominik ^_^ ^_^
--
Dominik Vogt
IBM Germany
prev parent reply other threads:[~2015-11-24 10:01 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-11-24 7:36 Dominik Vogt
2015-11-24 7:53 ` Simon Ruderich
2015-11-24 9:37 ` Peter Stephenson
2015-11-24 9:51 ` Dominik Vogt [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20151124095104.GA29881@linux.vnet.ibm.com \
--to=vogt@linux.vnet.ibm.com \
--cc=zsh-users@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).