zsh-users
 help / color / mirror / code / Atom feed
* Word splitting in parameter expansion
@ 2003-05-02 15:45 Björn Lindström
  2003-05-02 15:56 ` Peter Stephenson
  0 siblings, 1 reply; 5+ messages in thread
From: Björn Lindström @ 2003-05-02 15:45 UTC (permalink / raw)
  To: zsh-users

I've got this in my .zshrc:

    man() {
        screen -h 0 -t "man $@" man $@
    }

This works fine as long as I only supply the function with one argument,
such as "man access", but when I do "man 5 access", it interprets
"5 access" as one argument (even though that is not what I meant ;-).

I have read through the zshexpn man page, and tried quite a few
variations on this, but can't seem to figure it out. Can anyone help me
out?

-- 
Björn Lindström <bkhl@privat.utfors.se>
Home page: http://hem.fyristorg.com/bkhl/
Blog: http://bkhl.livejournal.com/
Elektrubadur demo: http://hem.fyristorg.com/bkhl/elektrubadur/


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

* Re: Word splitting in parameter expansion
  2003-05-02 15:45 Word splitting in parameter expansion Björn Lindström
@ 2003-05-02 15:56 ` Peter Stephenson
  2003-05-02 16:08   ` Lloyd Zusman
  0 siblings, 1 reply; 5+ messages in thread
From: Peter Stephenson @ 2003-05-02 15:56 UTC (permalink / raw)
  To: zsh-users

=?iso-8859-1?Q?Bj=F6rn_Lindstr=F6m?= wrote:
> I've got this in my .zshrc:
> 
>     man() {
>         screen -h 0 -t "man $@" man $@
>     }
> 
> This works fine as long as I only supply the function with one argument,
> such as "man access", but when I do "man 5 access", it interprets
> "5 access" as one argument (even though that is not what I meant ;-).

I don't think it's doing quite what you say (although you don't see what
options you have set), but I agree it won't do what you expect...

If the arguments are `5' and `access' I would expect the words to be
divided as:

screen
-h
0
-t
man 5
access
man
5
access

(which is certainly what I get with my option settings).  The problem is
that the argument to -t is being divided into two parts.  To prevent that
you need:

man() {
    screen -h 0 -t "man $*" man $@
}

Actually, that last argument could be $* as well; if you want to
maintain zero-length arguments it needs to be "$@".

-- 
Peter Stephenson <pws@csr.com>                  Software Engineer
CSR Ltd., Science Park, Milton Road,
Cambridge, CB4 0WH, UK                          Tel: +44 (0)1223 692070


**********************************************************************
The information transmitted is intended only for the person or
entity to which it is addressed and may contain confidential 
and/or privileged material. 
Any review, retransmission, dissemination or other use of, or
taking of any action in reliance upon, this information by 
persons or entities other than the intended recipient is 
prohibited.  
If you received this in error, please contact the sender and 
delete the material from any computer.
**********************************************************************


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

* Re: Word splitting in parameter expansion
  2003-05-02 15:56 ` Peter Stephenson
@ 2003-05-02 16:08   ` Lloyd Zusman
  2003-05-02 16:14     ` Peter Stephenson
  0 siblings, 1 reply; 5+ messages in thread
From: Lloyd Zusman @ 2003-05-02 16:08 UTC (permalink / raw)
  To: zsh-users

Peter Stephenson <pws@csr.com> writes:

> =?iso-8859-1?Q?Bj=F6rn_Lindstr=F6m?= wrote:
>> I've got this in my .zshrc:
>> 
>>     man() {
>>         screen -h 0 -t "man $@" man $@
>>     }
>> 
>> This works fine as long as I only supply the function with one argument,
>> such as "man access", but when I do "man 5 access", it interprets
>> "5 access" as one argument (even though that is not what I meant ;-).
>
> I don't think it's doing quite what you say (although you don't see what
> options you have set), but I agree it won't do what you expect...
>
> If the arguments are `5' and `access' I would expect the words to be
> divided as:
>
> screen
> -h
> 0
> -t
> man 5
> access
> man
> 5
> access

A small correction: I believe the args would actually be divided thusly:

screen
-h
0
-t
man 5 access
man
5
access

In the "man $@" portion above, the "$@" should be replaced with
"5 access".







> (which is certainly what I get with my option settings).  The problem is
> that the argument to -t is being divided into two parts.  To prevent that
> you need:
>
> man() {
>     screen -h 0 -t "man $*" man $@
> }
>
> Actually, that last argument could be $* as well; if you want to
> maintain zero-length arguments it needs to be "$@".
>
> -- 
> Peter Stephenson <pws@csr.com>                  Software Engineer
> CSR Ltd., Science Park, Milton Road,
> Cambridge, CB4 0WH, UK                          Tel: +44 (0)1223 692070
>
>
> **********************************************************************
> The information transmitted is intended only for the person or
> entity to which it is addressed and may contain confidential 
> and/or privileged material. 
> Any review, retransmission, dissemination or other use of, or
> taking of any action in reliance upon, this information by 
> persons or entities other than the intended recipient is 
> prohibited.  
> If you received this in error, please contact the sender and 
> delete the material from any computer.
> **********************************************************************

-- 
 Lloyd Zusman
 ljz@asfast.com


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

* Re: Word splitting in parameter expansion
  2003-05-02 16:08   ` Lloyd Zusman
@ 2003-05-02 16:14     ` Peter Stephenson
  2003-05-02 16:25       ` Lloyd Zusman
  0 siblings, 1 reply; 5+ messages in thread
From: Peter Stephenson @ 2003-05-02 16:14 UTC (permalink / raw)
  To: zsh-users

Lloyd Zusman wrote:
> A small correction: I believe the args would actually be divided thusly:

No, that's the whole point of the message.  The $@ in quotes institutes
word breaks between words of the arguments array.

-- 
Peter Stephenson <pws@csr.com>                  Software Engineer
CSR Ltd., Science Park, Milton Road,
Cambridge, CB4 0WH, UK                          Tel: +44 (0)1223 692070


**********************************************************************
The information transmitted is intended only for the person or
entity to which it is addressed and may contain confidential 
and/or privileged material. 
Any review, retransmission, dissemination or other use of, or
taking of any action in reliance upon, this information by 
persons or entities other than the intended recipient is 
prohibited.  
If you received this in error, please contact the sender and 
delete the material from any computer.
**********************************************************************


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

* Re: Word splitting in parameter expansion
  2003-05-02 16:14     ` Peter Stephenson
@ 2003-05-02 16:25       ` Lloyd Zusman
  0 siblings, 0 replies; 5+ messages in thread
From: Lloyd Zusman @ 2003-05-02 16:25 UTC (permalink / raw)
  To: zsh-users

Peter Stephenson <pws@csr.com> writes:

> Lloyd Zusman wrote:
>> A small correction: I believe the args would actually be divided thusly:
>
> No, that's the whole point of the message.  The $@ in quotes institutes
> word breaks between words of the arguments array.

Ah yes ... not enough sleep and too much coffee.  Sorry.


-- 
 Lloyd Zusman
 ljz@asfast.com


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

end of thread, other threads:[~2003-05-02 16:26 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-05-02 15:45 Word splitting in parameter expansion Björn Lindström
2003-05-02 15:56 ` Peter Stephenson
2003-05-02 16:08   ` Lloyd Zusman
2003-05-02 16:14     ` Peter Stephenson
2003-05-02 16:25       ` Lloyd Zusman

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