Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3623786
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T23:25:35+00:00 2026-05-18T23:25:35+00:00

I need to set a variable inside of a bash for loop, which for

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T23:25:36+00:00Added an answer on May 18, 2026 at 11:25 pm

    Use

    for lvl in 1 2 3 4 
    do
        key="UNLOCKED_${box}_$lvl"
    done
    
    1. You were missing “do”/”done” keywords wrapping around the loop body

    2. $box_$lvl is treated by bash as a variable with the name box_ followed by variable with the name lvl. This is because _ is a valid character in a variable name. To separate the variable name from following _, use ${varname} syntax as shown above

    3. {0..24} does not work in bash v2 (which our servers have here) though it works as a range shortcut on modern bash so that should not cause youproblems.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to set a system environment variable from a Bash script that would
I need to set up some RewriteRules to redirect a URL which has a
I need to set an environment variable in Python and find the address in
I need to set the height of every textbox on my form, some of
I need to use the value of a variable inside another variable. This is
i have a input tag which is non editable, but some times i need
Is there anything wrong with setting a Rails variable inside a javascript function? I
Overlooking something basic here but I am trying to set a variable and have
I'm in need to declare a local variable and test for it inside of
I have a set S of small trees S[i] which I need to find

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.