title: How do I set a variable inside a bash for loop?
body: <p>I need to set a variable inside of a bash for loop, which for some reason, is not working for me. Here is an excerpt of my script:</p>
  
  <pre><code>function unlockBoxAll
  {
  appdir=$(grep -i "CutTheRope.app" /tmp/App_list.tmp)
  for lvl in {0..24}
  key="UNLOCKED_$box_$lvl"
  plutil -key "$key" -value "1" "$appdir/../Library/Preferences/com.chillingo.cuttherope.plist" 2&gt;&amp;1&gt; /dev/null
  successCheck=$(plutil -key "$key" "$appdir/../Library/Preferences/com.chillingo.cuttherope.plist")
  if [ "$successCheck" -eq "1" ]; then
   echo "Success! "
      else
   echo "Failed: Key is $successCheck "
  fi
  done
  }
  </code></pre>
  
  <p>As you can see, I try to write to a variable inside the loop with:</p>
  
  <pre><code>key="UNLOCKED_$box_$lvl"
  </code></pre>
  
  <p>But when I do that, I get this:</p>
  
  <pre><code>/usr/bin/cutTheRope.sh: line 23: syntax error near unexpected token `key="UNLOCKED_$box_$lvl"'
  /usr/bin/cutTheRope.sh: line 23: `key="UNLOCKED_$box_$lvl"'
  </code></pre>
  
  <p>What am I not doing right? Is there another way to do this?</p>
  
  <p>Please help, thanks.</p>