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 9215517
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:13:17+00:00 2026-06-18T02:13:17+00:00

I need help incrementing array values inside loops. The problem is variables are all

  • 0

I need help incrementing array values inside loops. The problem is variables are all the same and the second element of “Numbers” array is not incremented.

#!/bin/bash

Duration=60

declare -a Numbers=("5" "10")

for (( d=1 ; d<=$Duration ; d++ ))
do

  for (( i=0 ; i<${#Numbers[@]} ; i++ ))
  do

        if [ "$MYVALA" == "" ]; then
                MYVALA=${Numbers[i]}
        else
                MYVALA=$(($MYVALA+1))
        fi ;

        echo ""
        echo "number: ${Numbers[i]}"
        echo "-------------"
        echo "new value = $MYVALA"
  done ;
  sleep 1 ;
done ;

this is the result of code above:

number: 5
-------------
new value = 5

number: 10
-------------
new value = 6

number: 5
-------------
new value = 7

number: 10
-------------
new value = 8

What I would like to get is:

number: 5
-------------
new value = 6

number: 10
-------------
new value = 11

number: 5
-------------
new value = 7

number: 10
-------------
new value = 12
...

number 5 and number 10 are printed at the same time and once per second.

Thanks for your help.

  • 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-06-18T02:13:18+00:00Added an answer on June 18, 2026 at 2:13 am

    This produces the output you wanted. The new value is simply the number plus duration.

    #!/bin/bash
    
    Duration=60
    Numbers=(5 10)
    
    for (( d=1 ; d<=Duration ; d++ )) ; do
      for (( i=0 ; i<${#Numbers[@]} ; i++ )) ; do
          let MYVALA=Numbers[i]+d
          echo
          echo "number: ${Numbers[i]}"
          echo '-------------'
          echo "new value = $MYVALA"
      done
      sleep 1
    done
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need help incrementing value of all keys in participants without having to know
Need help.. Please tell me why A.clear() does not clear the first column too?
Need help. I'm making electric billing system and I had a problem solving 2
Need help in getting the string[] values of node property?? for example I have
Need help with a problem. Goal I'm putting together an iOS book app that
Need help with the codeigniter, I think file_exists is for server path, not for
Need help, function getFamily() { FB.api('/me/family', function(response) { alert(JSON.stringify(response)); }); } With the above
Need help with a query that I wrote: I have three tables Company id
Need help getting Ember-Data working with Zend Rest. At first, I'm familiar with Zend
Need help on these 2 questions: If i am tracking a virtual pageview for

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.