From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 28226 invoked by alias); 7 Jul 2014 21:06:52 -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: 18930 Received: (qmail 23780 invoked from network); 7 Jul 2014 21:06:49 -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=-2.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 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== X-Received: by 10.140.29.66 with SMTP id a60mr49707280qga.76.1404767206580; Mon, 07 Jul 2014 14:06:46 -0700 (PDT) MIME-Version: 1.0 From: TJ Luoma Date: Mon, 7 Jul 2014 17:06:06 -0400 Message-ID: Subject: how do I get the last argument from a list of arguments? To: Zsh-Users List Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable I=E2=80=99m 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=3D"$1" shift ;; -v|--verbose) VERBOSE=3D'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=3D`echo "$@" | awk '{print $NF}'` but that made me wonder if there wasn=E2=80=99t 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