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:00:23 +0100

On Tue, 11 Jul 2023 23:15:52 +0200
alex xmb ratchev <fxmbsw7@gmail.com> wrote:

> On Tue, Jul 11, 2023, 22:05 Greg Wooledge <greg@wooledge.org> wrote:
> 
> > On Wed, Jul 12, 2023 at 02:54:10AM +0700, Budi wrote:
> > > How do we get state of a flag in set -o ... that has no directly alias
> > > set [-+] , e.g.
> > > set -o posix
> > > or
> > > set -o vi
> > > ?
> > >
> > > not, e.g. set -o errexit , as it can be retrieved by echo $-
> >
> > Parse the output of "set -o".
> >
> 
> i was trying some simple code but fatally failed
> 
> + ret
> ++ set -o
> + a=('allexport         off
> braceexpand     on
> emacs           on
> errexit         off
> errtrace        off
> functrace       off
> hashall         on
> histexpand      on
> history         on
> ignoreeof       off
> interactive-comments    on
> keyword         off                                               monitor
>        on                                                noclobber
>  off                                               noexec          off
>                                          noglob          off
>                                nolog           off
>                      notify          off
>            nounset         off
>  onecmd          off
>  physical        off
> pipefail        off
> posix           off
> privileged      off
> verbose         off
> vi              off
> xtrace          on')
> + declare -gA a
> + declare -p a
> declare -A a=([$'allexport      \toff\nbraceexpand    \ton\nemacs
> \ton\nerrexit        \toff\nerrtrace       \toff\nfunctrace
> \toff\nhashall        \ton\nhistexpand     \ton\nhistory
> \ton\nignoreeof      \toff\ninteractive-comments\ton\nkeyword
> \toff\nmonitor        \ton\nnoclobber      \toff\nnoexec
>  \toff\nnoglob         \toff\nnolog          \toff\nnotify
>  \toff\nnounset        \toff\nonecmd         \toff\nphysical
>  \toff\npipefail       \toff\nposix          \toff\nprivileged
>  \toff\nverbose        \toff\nvi             \toff\nxtrace
>  \ton']="" )
> ~ $ 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.

-- 
Kerin Millar



reply via email to

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