How do I set a variable inside a bash for loop?
- by Isaac Moore
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:
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>&1> /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
}
As you can see, I try to write to a variable inside the loop with:
key="UNLOCKED_$box_$lvl"
But when I do that, I get this:
/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"'
What am I not doing right? Is there another way to do this?
Please help, thanks.