[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: $IFS and "${array[@]:offset}"
From: |
Stephane Chazelas |
Subject: |
Re: $IFS and "${array[@]:offset}" |
Date: |
Fri, 6 Jun 2008 10:42:55 +0100 |
User-agent: |
Mutt/1.5.16 (2007-09-19) |
On Fri, Jun 06, 2008 at 11:08:23AM +0200, Andreas Schwab wrote:
> Stephane Chazelas <Stephane_Chazelas@yahoo.fr> writes:
>
> > It still doesn't explain why ${@:1:1} expands to $1 and not $2
>
> For positional parameters indexing starts at 1.
[...]
Alright sorry, that was me being confused. I thought
${array[@]:n:1} was giving the (n+1)th element of the array
while it's not, it's giving the first element whose index if
greater or equal to n.
I thought
$ bash -c 'a[1664]=x a[51]=4 a[42]=1; echo "${a[@]:1:1}"'
would give "4" because in the sorted list of indexes (42, 51,
1664), 51 is the second.
While it gives "1" because "42" is the first element after "1".
Sorry for the bother,
Stéphane