help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How do we get state of a flag in set -o ...


From: Kerin Millar
Subject: Re: How do we get state of a flag in set -o ...
Date: Tue, 11 Jul 2023 23:11:28 +0100

On Wed, 12 Jul 2023 00:03:14 +0200
alex xmb ratchev <fxmbsw7@gmail.com> wrote:

> >
> >
> > > ~ $ IFS=$' \t\n' ; ret() { declare -gA a=( $( set -o ) ) ; declare -p a
> > ; }
> > > ; sett() { declare -A m=( off + on - ) ; declare -ga args=( set ) ; for z
> > > in ${!a[@]} ; do declare -n "v=a[$z]" "mm=m[$v]" ; echo args+= ${mm}o
> > $z  ;
> > > done ; echo set "${args[@]}" ; } ; ret
> > >
> > > i didnt try without declare but ill try
> >
> > Let's use a more conventional definition of simple.
> >
> > $ declare -A map=( two words ); declare -p map
> > declare -A map=([two]="words" )
> >
> > $ declare -A map=( $(echo "two words") ); declare -p map
> > declare -A map=(["two words"]="" )
> >
> > $ declare -A map=(); map=( $(echo "two words") ); declare -p map
> > declare -A map=(["two words"]="" )
> >
> > This shows that the command substitution does not undergo a round of word
> > splitting in the case of an associative array, which I also find
> > surprising. I'm not sure whether it is intentional or not.
> >
> 
> weird .. this is a big problem to me .. i swear i had such parsing going
> for long
> since -A a=( var1 arg1 ) was introduced somewhen ..
> 
> its like the worlds reverse
> .. not the first time
> 
> =)

It is even true of variable expansion.

$ declare -A map; str="two words"; map=( $str ); declare -p map
declare -A map=(["two words"]="" )

It seems like a bug to me. It's certainly counter-intuitive. For indexed 
arrays, word splitting occurs. I see no particular reason for associative 
arrays to be a special case.

-- 
Kerin Millar



reply via email to

[Prev in Thread] Current Thread [Next in Thread]