Re: Unsetting all elements of an associative array

2015-03-10 Thread konsolebox
On Thu, Feb 5, 2015 at 11:02 PM, Chet Ramey wrote: > On 2/5/15 8:06 AM, isabella parakiss wrote: >> On 2/4/15, konsolebox wrote: >>> Logically that should only unset the elements of an array and not the >>> array variable >>> itself since '*' or '@' is more of a wildcard that represents the >>> i

Re: Unsetting all elements of an associative array

2015-02-05 Thread Chet Ramey
On 2/5/15 8:06 AM, isabella parakiss wrote: > On 2/4/15, konsolebox wrote: >> Logically that should only unset the elements of an array and not the >> array variable >> itself since '*' or '@' is more of a wildcard that represents the >> indices. However, bash >> does otherwise: >> >> #define A

Re: Unsetting all elements of an associative array

2015-02-05 Thread isabella parakiss
On 2/4/15, konsolebox wrote: > Logically that should only unset the elements of an array and not the > array variable > itself since '*' or '@' is more of a wildcard that represents the > indices. However, bash > does otherwise: > > #define ALL_ELEMENT_SUB(c)((c) == '@' || (c) == '*') > > .

Re: Unsetting all elements of an associative array

2015-02-04 Thread Chet Ramey
On 2/4/15 10:27 AM, Piotr Grzybowski wrote: > I think you are right, maybe this one should be considered: > > diff --git a/lib/sh/shquote.c b/lib/sh/shquote.c > index fff4f81..de05f27 100644 > --- a/lib/sh/shquote.c > +++ b/lib/sh/shquote.c > @@ -293,7 +293,7 @@ sh_contains_shell_metas (string) >

Re: Unsetting all elements of an associative array

2015-02-04 Thread Chet Ramey
On 2/4/15 9:42 AM, Greg Wooledge wrote: > imadev:~$ unset a; declare -A a; a=(["@"]=foo [!]=bar); declare -p a > declare -A a='([@]="foo" ["!"]="bar" )' > > imadev:~$ unset a; declare -A a='([@]="foo" ["!"]="bar" )' > bash: [@]="foo": invalid associative array key > > If the declare -p output is

Re: Unsetting all elements of an associative array

2015-02-04 Thread konsolebox
On Wed, Feb 4, 2015 at 4:12 PM, isabella parakiss wrote: > This produces an error: > $ declare -A array; unset array[@]; array[path/directory]=value > bash: path/directory: division by 0 (error token is "directory") > > After unsetting all its elements, the array is not associative anymore? Logic

Re: Unsetting all elements of an associative array

2015-02-04 Thread Piotr Grzybowski
I think you are right, maybe this one should be considered: diff --git a/lib/sh/shquote.c b/lib/sh/shquote.c index fff4f81..de05f27 100644 --- a/lib/sh/shquote.c +++ b/lib/sh/shquote.c @@ -293,7 +293,7 @@ sh_contains_shell_metas (string) case '(': case ')': case '<': case '>': cas

Re: Unsetting all elements of an associative array

2015-02-04 Thread Greg Wooledge
On Wed, Feb 04, 2015 at 03:37:07PM +0100, Piotr Grzybowski wrote: > On Wed, Feb 4, 2015 at 2:39 PM, Greg Wooledge wrote: > > > On that note, today I learned that you are not allowed to use either * > > or @ as the index of an associative array in bash. I guess I can see why, > > but... that's pr

Re: Unsetting all elements of an associative array

2015-02-04 Thread Piotr Grzybowski
On Wed, Feb 4, 2015 at 2:39 PM, Greg Wooledge wrote: > On that note, today I learned that you are not allowed to use either * > or @ as the index of an associative array in bash. I guess I can see why, > but... that's probably going to break something some day. :) of course you can ;-) decla

Re: Unsetting all elements of an associative array

2015-02-04 Thread Chet Ramey
On 2/4/15 8:39 AM, Greg Wooledge wrote: > On that note, today I learned that you are not allowed to use either * > or @ as the index of an associative array in bash. What caused you to believe that would work? -- ``The lyf so short, the craft so long to lerne.'' - Chaucer ``

Re: Unsetting all elements of an associative array

2015-02-04 Thread Greg Wooledge
On Wed, Feb 04, 2015 at 09:12:12AM +0100, isabella parakiss wrote: > I'm trying to use unset array[@] to empty an associative array, but something > goes wrong. What caused you to believe that would work? > This produces an error: > $ declare -A array; unset array[@]; array[path/directory]=value

Unsetting all elements of an associative array

2015-02-04 Thread isabella parakiss
I'm trying to use unset array[@] to empty an associative array, but something goes wrong. This behaves as expected: $ declare -A array; array[path/directory]=value This produces an error: $ declare -A array; unset array[@]; array[path/directory]=value bash: path/directory: division by 0 (error to