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: Chet Ramey
Subject: Re: Variable casts from string to array but silently fails in reverse
Date: Fri, 31 Jan 2014 14:45:03 -0500
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:24.0) Gecko/20100101 Thunderbird/24.1.1

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]