79073970

Date: 2024-10-10 10:37:07
Score: 0.5
Natty:
Report link

Similar to the solutions of @choroba and @ASarkar but modified to handle any special characters by shell-quoting expansion:

#!/bin/bash

function Dictionary_Builder() {
    declare -A dict=(['title']="Title of the song"
                 ['artist and "friends"']="Artist's song"
                 ['album']="Album of the song"
                )

    echo '('
    for key in  "${!dict[@]}" ; do
        echo "[${key@Q}]=${dict[$key]@Q}"
    done
    echo ')'
}

declare -A Output_Dictionary="$(Dictionary_Builder)"

for key in  "${!Output_Dictionary[@]}" ; do
    echo "${key}: '"${Output_Dictionary[$key]}"'"
done
Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • User mentioned (1): @choroba
  • User mentioned (0): @ASarkar
  • Low reputation (0.5):
Posted by: Stanislav German-Evtushenko