1

Similar to this Print array elements on separate lines in Bash? but printing only the keys.

The answer on that other one %s\n' "${myarray[@]}" when used on an associative array prints the values only while I'm looking for the keys.

declare -r -A myarray=(
   [a]=1
   [b]=2
   [c]=3
   [d]=4
)

Would like to have:

a
b
c
d
user5507535
  • 1,580
  • 1
  • 18
  • 39

1 Answers1

2

So just:

printf "%s\n" "${!myarray[@]}"
KamilCuk
  • 120,984
  • 8
  • 59
  • 111