* pop - is there a more elegant solution
@ 2001-06-28 8:01 jarausch
2001-06-28 8:04 ` Sven Wischnowsky
2001-06-28 8:23 ` Bart Schaefer
0 siblings, 2 replies; 3+ messages in thread
From: jarausch @ 2001-06-28 8:01 UTC (permalink / raw)
To: zsh-users
Hello,
just being curious,
is there a more elegant (less cryptic) solution to
#!/bin/zsh
# get the last parameter and shorten the list
# emulate Perl's pop function
echo $@
last=$[-1]
# shorten the parameter array
set $@[0,$[-1+$#]]
echo $@
Thanks for your opinion,
Helmut Jarausch
--
Helmut Jarausch
Lehrstuhl fuer Numerische Mathematik
Institute of Technology, RWTH Aachen
D 52056 Aachen, Germany
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: pop - is there a more elegant solution
2001-06-28 8:01 pop - is there a more elegant solution jarausch
@ 2001-06-28 8:04 ` Sven Wischnowsky
2001-06-28 8:23 ` Bart Schaefer
1 sibling, 0 replies; 3+ messages in thread
From: Sven Wischnowsky @ 2001-06-28 8:04 UTC (permalink / raw)
To: zsh-users
jarausch@igpm.rwth-aachen.dejarausch@igpm.rwth-aachen.de wrote:
> Hello,
>
> just being curious,
> is there a more elegant (less cryptic) solution to
>
> #!/bin/zsh
> # get the last parameter and shorten the list
> # emulate Perl's pop function
> echo $@
> last=$[-1]
> # shorten the parameter array
> set $@[0,$[-1+$#]]
> echo $@
>
> Thanks for your opinion,
Not much less cryptic:
last="$argv[-1]"
argv[-1]=()
Bye
Sven
--
Sven Wischnowsky wischnow@informatik.hu-berlin.de
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: pop - is there a more elegant solution
2001-06-28 8:01 pop - is there a more elegant solution jarausch
2001-06-28 8:04 ` Sven Wischnowsky
@ 2001-06-28 8:23 ` Bart Schaefer
1 sibling, 0 replies; 3+ messages in thread
From: Bart Schaefer @ 2001-06-28 8:23 UTC (permalink / raw)
To: jarausch, zsh-users
On Jun 28, 10:01am, jarausch@igpm.rwth-aachen.de 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
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2001-06-28 8:28 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-06-28 8:01 pop - is there a more elegant solution jarausch
2001-06-28 8:04 ` Sven Wischnowsky
2001-06-28 8:23 ` Bart Schaefer
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).