zsh-users
 help / color / mirror / code / Atom feed
* Nested quotes
@ 2015-11-24  7:36 Dominik Vogt
  2015-11-24  7:53 ` Simon Ruderich
  2015-11-24  9:37 ` Peter Stephenson
  0 siblings, 2 replies; 4+ messages in thread
From: Dominik Vogt @ 2015-11-24  7:36 UTC (permalink / raw)
  To: Zsh Users

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.

Ciao

Dominik ^_^  ^_^


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Nested quotes
  2015-11-24  7:36 Nested quotes Dominik Vogt
@ 2015-11-24  7:53 ` Simon Ruderich
  2015-11-24  9:37 ` Peter Stephenson
  1 sibling, 0 replies; 4+ messages in thread
From: Simon Ruderich @ 2015-11-24  7:53 UTC (permalink / raw)
  To: Zsh Users

[-- Attachment #1: Type: text/plain, Size: 485 bytes --]

On Tue, Nov 24, 2015 at 08:36:27AM +0100, Dominik Vogt 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'

Works fine for me without any extra quotes in zsh. In shell/bash
you need more quotes:

    echo "$(readlink -f "$file")"

Regards
Simon
-- 
+ privacy is necessary
+ using gnupg http://gnupg.org
+ public key id: 0x92FEFDB7E44C32F9

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Nested quotes
  2015-11-24  7:36 Nested quotes Dominik Vogt
  2015-11-24  7:53 ` Simon Ruderich
@ 2015-11-24  9:37 ` Peter Stephenson
  2015-11-24  9:51   ` Dominik Vogt
  1 sibling, 1 reply; 4+ messages in thread
From: Peter Stephenson @ 2015-11-24  9:37 UTC (permalink / raw)
  To: Zsh Users

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

but you might want to consider

  unsetopt shwordsplit

particularly if other people are using your zsh scripts functions.

It's also possible to turn SH_WORD_SPLIT off for one substitution,

  echo "$(readline -f ${==FILE}"

but that's got no obvious advantage here over simply quoting it, and
it's not portable.  The only advantage I can see is it's explicit to a
seasoned zsh user what you're trying to do.

pws


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Nested quotes
  2015-11-24  9:37 ` Peter Stephenson
@ 2015-11-24  9:51   ` Dominik Vogt
  0 siblings, 0 replies; 4+ messages in thread
From: Dominik Vogt @ 2015-11-24  9:51 UTC (permalink / raw)
  To: zsh-users

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


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2015-11-24 10:01 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-11-24  7:36 Nested quotes Dominik Vogt
2015-11-24  7:53 ` Simon Ruderich
2015-11-24  9:37 ` Peter Stephenson
2015-11-24  9:51   ` Dominik Vogt

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