From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 16656 invoked by alias); 7 Jul 2014 22:21:57 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 18933 Received: (qmail 4337 invoked from network); 7 Jul 2014 22:21:54 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 X-Originating-IP: [86.6.157.246] X-Spam: 0 X-Authority: v=2.1 cv=Mv/c6gqe c=1 sm=1 tr=0 a=BvYiZ/UW0Fmn8Wufq9dPrg==:117 a=BvYiZ/UW0Fmn8Wufq9dPrg==:17 a=NLZqzBF-AAAA:8 a=MRmYUYP1KqAA:10 a=uObrxnre4hsA:10 a=pAOpa0-fG8b0G26QHL0A:9 a=_dQi-Dcv4p4A:10 Message-Id: <201407072135.s67LZhcv006531@pws-pc.ntlworld.com> X-Authentication-Warning: pws-pc.ntlworld.com: pws owned process doing -bs From: Peter Stephenson To: Zsh-Users List Subject: Re: how do I get the last argument from a list of arguments? In-Reply-To: Message from TJ Luoma of "Mon, 07 Jul 2014 17:06:06 EDT." Date: Mon, 07 Jul 2014 22:35:43 +0100 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 Web page now at http://homepage.ntlworld.com/p.w.stephenson/