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

Re: how do I get the last argument from a list of arguments?



TJ Luoma wrote:
> 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.

The arguments are available as the array argv, so use $argv[-1].

-- 
Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/



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