From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 539 invoked by alias); 23 Sep 2015 19:46:01 -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: 20636 Received: (qmail 3206 invoked from network); 23 Sep 2015 19:46:00 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.0 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:message-id:date:in-reply-to:comments :references:to:subject:mime-version:content-type; bh=Kcun9uLnqIC3rFnRLxaMPkVt3RuuowvYTHQjvmP8vjU=; b=kEBxQsvMwqEhB6VAKVh5r8HOmaqsV56d70U2tq1HApGUVhSfSpfxMnE29X3Eek/rjv /42g75N5nzI8bSN86v4oOZZSVijioULfxRj5FzE6J6Wy9Re+dVN+VV7Mfj1E44JiGWM0 x5ioWEnSidOsrzHjJSG7q35gZZYa1D7do/ig427t+EtRhRu62uhCMKx7Ovw1OY9L+4lv s67xQ582D8pBr7XgSw/72BMHeFozjSMRFpwvkjrdLmCIkPt6SwlRsT05DRrYUGNexEOE ORXmMA2drgEjwmAVedaWnHndx6t7Z5+VZSyHVyOQYf2mVHh7GVcYawoYRfFibmH8qjuC EDHw== X-Gm-Message-State: ALoCoQmFCXE++3svbD8PpeQf/CTGr1qPOp7QKt3wE67mvLHlWyXV79WcGwP8y9VZ8CM2SSchgpwY X-Received: by 10.60.37.233 with SMTP id b9mr12222427oek.66.1443037555983; Wed, 23 Sep 2015 12:45:55 -0700 (PDT) From: Bart Schaefer Message-Id: <150923124553.ZM32030@torch.brasslantern.com> Date: Wed, 23 Sep 2015 12:45:53 -0700 In-Reply-To: <5602CC56.8080501@eastlink.ca> Comments: In reply to Ray Andrews "easy" (Sep 23, 8:59am) References: <20150911191854.59bcadb5@ntlworld.com> <5602CC56.8080501@eastlink.ca> X-Mailer: OpenZMail Classic (0.9.2 24April2005) To: zsh-users@zsh.org Subject: Re: easy MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii On Sep 23, 8:59am, Ray Andrews wrote: } Subject: easy } } $ test () { echo @[2,-1]; } Presume you're missing a $ in $@ there ... } $ test one two three four five } two three four five } } ... why is it that the leading number works intuitively but the second } one is 'off by one' so to speak? If you grasp that indexing from the left starts at one rather than at zero, why is it not "intuitive" that indexing from the right also starts at (negative) one rather than zero? Note that there is no zero'th position in $* / $@ / $argv -- the use of $0 as name of shell / script / function is just a convention. (Unless you setopt ksharrays, but then $0 and ${argv[0]} are two very different things, and even in ksh itself reverse index starts at -1.) In any case mathematically +0 == -0 so if you think of them as array positions those ought to refer to the same place (which in this case is nothing, because there is no position zero). Where you came up with thinking in terms of something being "removed from the array" baffles me. Nothing is "removed" from the original array in either case; the indices identify what is *included* in the result. I suppose you're expecting ${argv[-1]} congruent with ${argv[$# - 1]} and if ksharrays is set that works out to be true (but then $@[2] would not mean what it does in your example, either).