help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-bash] declare -i


From: Bill Gradwohl
Subject: Re: [Help-bash] declare -i
Date: Thu, 10 May 2012 07:08:06 -0600

On Thu, May 10, 2012 at 6:08 AM, Greg Wooledge <address@hidden> wrote:
On Wed, May 09, 2012 at 07:18:51PM -0600, Bill Gradwohl wrote:
> array[-1]=blahBlah

Array indices have to be non-negative integers.  If you want to use
negative integers as indices, then you must do it with an associative
array (in which case -1 would be treated as a two-character string).


# Walk the array backwards:
array=(11 12 13 14 15)
for ((x=1; x<address@hidden; ++x)); do
   echo ${array[-x]}
done

Outputs:
address@hidden ycc# ./tst
15
14
13
12
11


If they work just fine on the right hand side, why not on the left?

The docs say this is legal, just don't mention its only legal on the RHS.


These anomalies should simply be documented and listed so when people stumble over them they have a ready reference to check to see if its just anomalous behavior or something else.

--
Bill Gradwohl


reply via email to

[Prev in Thread] Current Thread [Next in Thread]