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

  • Home
  • SEARCH
  • 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 6230795
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T09:48:59+00:00 2026-05-24T09:48:59+00:00

This is my first time using Bash, so bear with me. I’m using Git

  • 0

This is my first time using Bash, so bear with me. I’m using Git Bash in Windows for a college project, trying to rewrite some C code that provides an alternate way of multiplying two numbers “a” and “b” to produce “c”. This is what I came up with:

#!/bin/bash

declare -i a
declare -i b
declare -i c=0
declare -i i=0    # not sure if i have to initialize this as 0?
echo "Please enter a number: "
read a
echo "Please enter a number: "
read b

for i in {1..b}
do
    let "c += a"
done

echo "$a x $b = $c"

I think part of the problem is in the for loop, that it only executes once. This is my first time using Bash, and if anyone could find the fault in my knowledge, that would be all I need.

  • 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-24T09:49:00+00:00Added an answer on May 24, 2026 at 9:49 am

    for i in {1..b}

    won’t work, because ‘b’ isn’t interpreted as a variable but a character to iterate to.
    For instance {a..c} expands to a b c.

    To make the brace expansion work:
    for i in $(eval echo “{1..$b}”)

    The let “c += a” won’t work either.
    let c+=$a might work, but I like ((c+=a)) better.

    Another way is this:


    for ((i = 1; i <= b; i++))
    do
        ((c += a))
    done

    (might need to put #!/bin/bash at the top of your script, because sh does less than bash.)

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

Sidebar

Related Questions

This is my first time using any sort of version control (git) and excited
This is my first time using nginx and I'm having some problems configuring an
This is my first time using a webservice and I' trying to create a
This is my first time using the Entity Framework and I'm getting some confusing
This is my first time using joomla. I don't know if I'm using the
This is my first time using the synchronized keyword, so I am still unsure
this is my first time using Eclipse, and my first time programming in a
This is my first time using Zend Framework for an application and i don't
This is my first time using JQuery in any of my projects. I have
This is my first time using SAXParser, (I'm using it in Android, but I

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.