[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Organising conditions
From: |
Greg Wooledge |
Subject: |
Re: Organising conditions |
Date: |
Mon, 2 Aug 2021 14:33:39 -0400 |
On Mon, Aug 02, 2021 at 06:17:43PM +0000, hancooper wrote:
> declare -A aa=([a]="Joe" [b]="Peter" [c]="Sammy")
> keyv ${aa[@]}
>
> I get no output.
unicorn:~$ keyv() {
local -n _keyv_array="$1"
local _keyv_key
for _keyv_key in "${!_keyv_array[@]}"; do
printf 'Key: %s\n' "$_keyv_key"
printf 'Value: %s\n' "${_keyv_array[$_keyv_key]}"
done
}
unicorn:~$ keyv aa
Key: 1
Value: 3
Key: x
Value: y
unicorn:~$ declare -p aa
declare -A aa=([1]="3" [x]="y" )
And here's the dreaded name collision:
unicorn:~$ keyv _keyv_array
bash: local: warning: _keyv_array: circular name reference
bash: warning: _keyv_array: circular name reference
bash: warning: _keyv_array: circular name reference
That's why I mangled the local variable names. It's done to protect
against *that*, or worse.
- Re: Organising conditions, (continued)
- Re: Organising conditions, hancooper, 2021/08/02
- Re: Organising conditions, Greg Wooledge, 2021/08/02
- Re: Organising conditions, hancooper, 2021/08/02
- Re: Organising conditions, Greg Wooledge, 2021/08/02
- Re: Organising conditions, hancooper, 2021/08/02
- Re: Organising conditions, Greg Wooledge, 2021/08/02
- Re: Organising conditions, Leonid Isaev (ifax), 2021/08/02
- Re: Organising conditions, hancooper, 2021/08/02
- Re: Organising conditions, Greg Wooledge, 2021/08/02
- Re: Organising conditions, hancooper, 2021/08/02
- Re: Organising conditions,
Greg Wooledge <=
- Re: Organising conditions, hancooper, 2021/08/02
- Re: Organising conditions, Greg Wooledge, 2021/08/02
- Re: Organising conditions, hancooper, 2021/08/02