[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Warn upon "declare -ax"
From: |
Martin D Kealey |
Subject: |
Re: Warn upon "declare -ax" |
Date: |
Wed, 6 Sep 2023 06:25:28 +1000 |
On Wed, 6 Sep 2023, 01:46 Kerin Millar, <kfm@plushkava.net> wrote:
> My pet name for it is arrayshock.
>
> $ arr=(foo bar baz)
> $ export arr
> $ env | grep ^BASH_ARRAY_
> BASH_ARRAY_arr%%=([0]="foo" [1]="bar" [2]="baz")
> $ ./bash -c 'declare -p arr'
> declare -ax arr=([0]="foo" [1]="bar" [2]="baz")
>
I've often wondered why it was designed this convoluted way, rather than
simply putting separate items into the environment, thus:
arr=foo
arr[0]=foo # both of these have reasonable justifications and reasonable
repudiations; choosing one is a different discussion
arr[1]=bar
arr[2]=baz
arr-=a # maybe, to indicate declare -a.
I vaguely recall that there was some notion that POSIX required "only valid
C identifiers" (alphanumeric and underscore but without a leading digit) to
the left of "=", but in that case the current scheme using "%%" is not
compliant either.
-Martin
>
Message not available