title: How to print out key values in bash?
body: <p>Let's say for example I have the following code:</p>
  
  <pre><code>arr=([j1]=3 [j2]=2 [j3]=1)
  </code></pre>
  
  <p>How do I print out the key values (j1, j2, j3)?</p>
  
  <p>I tried this:</p>
  
  <pre><code>for key in ${!arr[@]}; do
      echo ${key}
  done
  </code></pre>
  
  <p>It printed out the following:</p>
  
  <pre><code>0
  </code></pre>
  
  <p>How do I print out all of the key values and not the index number?</p>
  
  <p>EDIT1:</p>
  
  <p>I tried some of the suggestions and my full code is now as follows:</p>
  
  <pre><code>#!/bin/bash
  
  #Suggestion 2
  declare -A arr
  
  arr=([j1]=3 [j2]=2 [j3]=1)
  
  
  #My original code
  for key in ${!arr[@]}; do
      echo ${key}
  done
  
  
  #Suggestion 1
  for i in "${!arr[@]}"
  do
      echo "key: $i"
      echo "value: ${arr[$i]}"
  done
  </code></pre>
  
  <p>I have two for loops that theoretically should print out my key values, but I am still getting the following:</p>
  
  <pre><code>0
  </code></pre>
  
  <p>What is wrong with my code?</p>