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?
- X-seq: zsh-users 18933
- From: Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx>
- To: Zsh-Users List <zsh-users@xxxxxxx>
- Subject: Re: how do I get the last argument from a list of arguments?
- Date: Mon, 07 Jul 2014 22:35:43 +0100
- In-reply-to: Message from TJ Luoma <luomat@gmail.com> of "Mon, 07 Jul 2014 17:06:06 EDT." <CADjGqHuALx7Ue3Ei3s7XvT_pHWxECo2rt=BNegPO5Fwcuge2LQ@mail.gmail.com>
- 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
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