bug-bash
[Top][All Lists]
Advanced

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

Re: Variable casts from string to array but silently fails in reverse


From: Jonathan Doull
Subject: Re: Variable casts from string to array but silently fails in reverse
Date: Fri, 31 Jan 2014 20:36:00 +0000

Thanks - understandable although was confusing at the time and made for a
nasty subtle scripting bug.

Bash is not for the faint hearted.


On 31 January 2014 19:45, Chet Ramey <chet.ramey@case.edu> wrote:

> On 1/31/14 10:39 AM, Jonathan Doull wrote:
>
> > Bash Version: 4.2
> > Patch Level: 25
> > Release Status: release
> >
> > Description:
> >
> > Variables can be automatically cast from string to array.
> > However when cast from array to string, the cast silently fails.
>
> Not quite.  The bash man page says:
>
> "Referencing an array variable without a subscript is equivalent to
> referencing the array with a subscript of 0."
>
> This works for both obtaining and assigning values.  So, you are partially
> correct: assigning to a variable using array assignment syntax converts
> it to an array.  However, once a variable has been converted to an
> array, references without subscripts are equivalent to ${array[0]} or
> array[0]=value.
>
> Chet
> --
> ``The lyf so short, the craft so long to lerne.'' - Chaucer
>                  ``Ars longa, vita brevis'' - Hippocrates
> Chet Ramey, ITS, CWRU    chet@case.edu
> http://cnswww.cns.cwru.edu/~chet/
>


reply via email to

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