Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: pop - is there a more elegant solution
- X-seq: zsh-users 3969
- From: "Bart Schaefer" <schaefer@xxxxxxxxxxxxxxxxxxxxxxx>
- To: jarausch@xxxxxxxxxxxxxxxxxxx, zsh-users@xxxxxxxxxx
- Subject: Re: pop - is there a more elegant solution
- Date: Thu, 28 Jun 2001 08:23:48 +0000
- In-reply-to: <200106280801.KAA63855@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- References: <200106280801.KAA63855@xxxxxxxxxxxxxxxxxxxxxxxxx>
On Jun 28, 10:01am, jarausch@xxxxxxxxxxxxxxxxxxx wrote:
}
} is there a more elegant (less cryptic) solution to
} # emulate Perl's pop function
Depends on what you intend by emulating it. Functions in Bourne-like
shell languages don't return values like functions in perl, so there
isn't anything well-defined to do with the popped value.
The fastest way to simply discard the last positional parameter is
argv[-1]=()
(which of course only works in zsh). So if what you want to do is to
store that positional parameter in $last and then discard it,
last=$argv[-1]
argv[-1]=()
is about as un-cryptic as you're going to get.
} #!/bin/zsh
} # get the last parameter and shorten the list
} echo $@
} last=$[-1]
You must mean $@[-1]. $[-1] is just -1. But if you know about $@[-1],
then ...
} # shorten the parameter array
} set $@[0,$[-1+$#]]
... you should know that $@[1,-2] works as well. (You don't index from
zero unless the ksh_arrays option is set.)
Aside to zsh-workers: A weird thing about `setopt ksharrays' is that
${@[0]} is $1. Does ksh really work that way?
--
Bart Schaefer Brass Lantern Enterprises
http://www.well.com/user/barts http://www.brasslantern.com
Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net
Messages sorted by:
Reverse Date,
Date,
Thread,
Author