zsh-workers
 help / color / mirror / code / Atom feed
From: Zefram <zefram@fysh.org>
To: =?unknown-8bit?Q?Ra=FAl_N=FA=F1ez?= de Arenas Coronado
	<raul@viadomus.com>
Cc: Zsh <zsh-workers@sunsite.dk>
Subject: Re: About quoting
Date: Wed, 2 Jan 2002 21:05:24 +0000	[thread overview]
Message-ID: <20020102210524.GA28822@fysh.org> (raw)
In-Reply-To: <E16Ls9O-0004kV-00@DervishD.viadomus.com>

Ra?l N??ez de Arenas Coronado wrote:
>    $ export PAGER="/my/pager --flag --otherflag -"
>    $ ls | $PAGER
>
>    The matter here, I think, is that spaces remains quoted when
>doing the expansion in the redirection.

You're correct in identifying the effect, but the cause isn't quite
what you think.  The quoting isn't relevant here, it's not part of the
variable's value.  What's actually happening is that zsh simply isn't
dividing up the expanded value at spaces, which bash does.

There are several solutions.  If you want to divide up a scalar value
in that way, add an "=" after the "$", so

	$ ls | $=PAGER

will do what you want.  You can also set the option SH_WORD_SPLIT, which
does this automatically for all variable substitutions, but this is a bad
idea, because it's often useful to retain spaces in a variable expansion.
(This option is turned on automatically if zsh is invoked under the name
"bash", "sh", or "ksh", for compatibility.)

Another way to do what you want is to define an array variable, which
will be substituted as separate words:

	$ pager=(/my/pager --flag --otherflag -)
	$ ls | $pager

This has the advantage that the words can contain spaces.  However,
arrays cannot be exported.

For the use you're making of the variable here, the proper solution is
actually a shell function:

	$ function pager {
	>   /my/pager --flag --otherflag -
	> }
	$ ls | pager

If you want to use the standard $PAGER variable from within the shell,
with it set the way you describe, I think the neatest solution is to
hide the $=PAGER expansion in a shell function:

	$ export PAGER="/my/pager --flag --otherflag -"
	$ function pager {
	>   $=PAGER
	> }
	$ ls | pager

But you should also consider that some programs that use $PAGER won't
interpret it the way you intend.  You'd be better off putting the complex
command into a shell script, and putting the path of that script into
$PAGER.

-zefram


  reply	other threads:[~2002-01-02 21:05 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-01-02 20:38 Raúl Núñez de Arenas Coronado
2002-01-02 21:05 ` Zefram [this message]
2002-01-02 21:32 Raúl Núñez de Arenas Coronado

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=20020102210524.GA28822@fysh.org \
    --to=zefram@fysh.org \
    --cc=raul@viadomus.com \
    --cc=zsh-workers@sunsite.dk \
    /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).