bug-bash
[Top][All Lists]
Advanced

[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 09:51:56 +0100
User-agent: Mutt/1.5.16 (2007-09-19)

On Fri, Jun 06, 2008 at 10:38:41AM +0200, Andreas Schwab wrote:
> Stephane Chazelas <stephane_chazelas@yahoo.fr> writes:
> 
> > The behavior is the same in ksh, but in ksh ${@:0:1} expands to
> > $0 which makes it more understandable ($0 has its meaning in
> > functions as well in ksh which makes it somehow consistent).
> >
> > In bash, ${@:0:1} and ${@:1:1} expand to the same thing ($1). Is
> > all that documented (I couldn't find it via a quick scan of the
> > man page)?
> 
> $@ expands to the positional parameters, which $0 is not (it is a
> special parameter).  Since index 0 does not exist, $1 is the first
> counted parameter in the expansion.
[...]

You make me remember that I had forgotten that aspect of ksh and
bash arrays in that they are associative arrays (contrary to
zsh's) with keys being only positive of null integers.

${a[0]} is the element of key 0. ${a[@]:0:1} is the first
element of the list of $a elements numerically sorted by their
keys. And ${a[@]:1:1} is the second element.

It still doesn't explain why ${@:1:1} expands to $1 and not $2
(if we assume that $0 is not part of $@ which I agree).

-- 
Stéphane




reply via email to

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