Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
how do I get the last argument from a list of arguments?
- X-seq: zsh-users 18930
- From: TJ Luoma <luomat@xxxxxxxxx>
- To: Zsh-Users List <zsh-users@xxxxxxx>
- Subject: how do I get the last argument from a list of arguments?
- Date: Mon, 7 Jul 2014 17:06:06 -0400
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:from:date:message-id:subject:to:content-type :content-transfer-encoding; bh=vAWCwsJXfsUUtIattYzMy8qP8REVQxbQQ/Rw1OfoD7w=; b=j6F29vnSgNsyf7+a392J0Tic/UGuRBCpaB2eOz7182FOv0iwc5KblwesbigCtXrDTt cX8PTRO+Mgrloa19fkEz/SRJHht++qaNdQ0eiHVPmlc5fsmaqPxcqiDQBmCTkjLVA6Pk 9DFMBSuBewO60y3V4qOGL7yiiGb+FMdBS8WA5degBAncvnDNAeqYpYBsQeRslh9CjpSh 1ZvdENi2JBDZE6w+fa9DAqjaI2qq4H2OOYm+MnMHHbqg7EmGo0jaOXds2m2tGlf8cKET N5NveLq1UH/Yu7Zuu+/nz/JRwNd7nCrzJIGxJkZ/WKXN3NN/Tuq4OSmSkEqn2sLEjb7z TtxA==
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
I’m trying to learn better ways of dealing with arguments given to a
function, because I am sure that I am not doing it the most efficient
way.
For example, if I want to process a series of args, I usually use a
loop like this:
for FOO in "$@"
do
case "$FOO" in
-t|--to)
shift
TO="$1"
shift
;;
-v|--verbose)
VERBOSE='yes'
shift
;;
-*|--*)
echo " $NAME [warning]: Don't know what to do with arg: $1"
shift
;;
esac
done # for args
That has worked OK for what I've needed to do, but now I'm trying to
create two functions which I will use in place of 'cp' and 'mv' and I
need to be able to find the _last_ argument (the destination) before I
process all the rest of the args.
The only way that I can think of to get the last argument is to do
something like this
LAST=`echo "$@" | awk '{print $NF}'`
but that made me wonder if there wasn’t a better way.
Note that this does not need to be 'portable' at all -- I will happily
use any zsh-specific features which may exist, as long as it works in
5.0.2 (which is what comes with OS X).
Thanks!
TjL
Messages sorted by:
Reverse Date,
Date,
Thread,
Author