Le Mon, Dec 22, 2025 at 08:01:13PM +0100, Félix Hauri via Bug reports for the 
GNU Bourne Again SHell a écrit :
> Note: there's no ``eval'', but `declare -A` work like an eval!
> If instead of ``%q'', I've used ``%s'', then ``$(date)'' will be executed!
> 
>   $ declare -A aa=( empty '' inject '$(date)' "space key" "space value" \
>         lb \[ rb \] punc $' \t\n' )
>   $ printf -v tmpString '[%q]="%s" ' "${aa[@]@k}"
>   $ declare -A "newarray=($tmpString)"
>   $ declare -p newarray
>   declare -A newarray=([inject]="Mon Dec 22 19:57:41 CET 2025" [lb]="[" 
> ["space ke
>   y"]="space value" [empty]="" [punc]=$' \t\n' [rb]="]" )
Or even:

  $ declare -A aa=( empty '' inject '$(date)' "space key" "space value"  \
        '$(uptime)' injected  lb \[ rb \] punc $' \t\n' )
  $ printf -v tmpString '["%s"]="%s" ' "${aa[@]@k}"
  $ declare -A "newarray=($tmpString)"
  $ declare -p newarray
  declare -A newarray=([inject]="Mon Dec 22 20:16:59 CET 2025" [lb]="[" ["space 
ke
  y"]="space value" [empty]="" [punc]=$' \t\n' [rb]="]" [" 20:16:59 up 1 days, 
10:
  18, 1 users,  load average: 0.18, 0.12, 0.23"]="injected" )


--
 Félix Hauri

  • Re: Question a... Greg Wooledge
    • Re: Quest... Koichi Murase
      • Re: Q... Greg Wooledge
        • R... Zachary Santer
          • ... Greg Wooledge
        • R... Koichi Murase
          • ... Koichi Murase
        • R... Félix Hauri via Bug reports for the GNU Bourne Again SHell
          • ... Greg Wooledge
            • ... Félix Hauri via Bug reports for the GNU Bourne Again SHell
              • ... Félix Hauri via Bug reports for the GNU Bourne Again SHell
              • ... Greg Wooledge

Reply via email to