zsh-workers
 help / color / mirror / code / Atom feed
* About quoting
@ 2002-01-02 20:38 Raúl Núñez de Arenas Coronado
  2002-01-02 21:05 ` Zefram
  0 siblings, 1 reply; 3+ messages in thread
From: Raúl Núñez de Arenas Coronado @ 2002-01-02 20:38 UTC (permalink / raw)
  To: Zsh

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 659 bytes --]

    Hello all zshworkers :))

    First of all, happy new year :)

    I have a little problem with quoting. I'm not understanding
something about it. With Bash I can do the following:

    $ export PAGER="/my/pager --flag --otherflag -"
    $ ls | $PAGER

    And it works. But under zsh, when doing the redirection above,
the shell complains 'no such file or directory: /my/pager --flag...'.

    The matter here, I think, is that spaces remains quoted when
doing the expansion in the redirection. Anyway, I need to quote the
spaces in order to define de variable, or zsh will complain then.

    How can I do this with zsh?

    Thanks a lot :)

    Raúl


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

* Re: About quoting
  2002-01-02 20:38 About quoting Raúl Núñez de Arenas Coronado
@ 2002-01-02 21:05 ` Zefram
  0 siblings, 0 replies; 3+ messages in thread
From: Zefram @ 2002-01-02 21:05 UTC (permalink / raw)
  To: =?unknown-8bit?Q?Ra=FAl_N=FA=F1ez?= de Arenas Coronado; +Cc: Zsh

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


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

* Re: About quoting
@ 2002-01-02 21:32 Raúl Núñez de Arenas Coronado
  0 siblings, 0 replies; 3+ messages in thread
From: Raúl Núñez de Arenas Coronado @ 2002-01-02 21:32 UTC (permalink / raw)
  To: raul, zefram; +Cc: zsh-workers

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 621 bytes --]

    Hi Zefram :))

    Thanks a lot for your answer, fast and good :))

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

    This will do, since none of my binaries (AFAIK) use $PAGER thru
the shell...

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

    Anyway, I need bash compatibility, so this is not a bad idea too.

    I'll try the second solution first.

    Thanks a lot again :))

    Raúl


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

end of thread, other threads:[~2002-01-02 21:20 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-01-02 20:38 About quoting Raúl Núñez de Arenas Coronado
2002-01-02 21:05 ` Zefram
2002-01-02 21:32 Raúl Núñez de Arenas Coronado

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