[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
readonly inconsistency with arrays
From: |
Will Allan |
Subject: |
readonly inconsistency with arrays |
Date: |
Mon, 3 Jun 2024 21:54:14 +0000 (UTC) |
I'm seeing what appears to be an inconsistency with using `readonly` on
variables declared in a previous scope.
declare stringdeclare -i intdeclare -a array
init_vars () { readonly string="foo" readonly int=100 readonly array=(1 2)
# Print the (hopefully) readonly variables declare -p string int array}
init_vars
This prints the expected output (IMO):
declare -r string="foo"declare -ir int="100"declare -ar array=([0]="1" [1]="2")
Now if I attempt to do the same for local variables declared as such:
foo () { local string local -i int local -a array
init_vars}
foo
This prints different output for the indexed array only:
declare -r string="foo"declare -ir int="100"declare -ar array
Things get even more confusing if I declare an associative array, which
readonly seems to think is now an indexed array, but maybe that's a different
issue.
Thoughts?
TIA,
Will
- readonly inconsistency with arrays,
Will Allan <=
- Re: readonly inconsistency with arrays, Zachary Santer, 2024/06/03
- Re: readonly inconsistency with arrays, Chet Ramey, 2024/06/04
- REQUEST, Saint Michael, 2024/06/04
- REQUEST - bash floating point math support, Zachary Santer, 2024/06/05
- Re: REQUEST - bash floating point math support, Koichi Murase, 2024/06/05
- Re: REQUEST - bash floating point math support, Léa Gris, 2024/06/06
- Re: REQUEST - bash floating point math support, Koichi Murase, 2024/06/06
- Re: REQUEST - bash floating point math support, Léa Gris, 2024/06/06