Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Word splitting in parameter expansion



Peter Stephenson <pws@xxxxxxx> 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@xxxxxxx>                  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@xxxxxxxxxx



Messages sorted by: Reverse Date, Date, Thread, Author