0

I am trying to make a user input increment however, if I tried a variable in the increment, it does not work. How to make it work?

My script:

#!/bin/bash
input=$(echo "$((2*100))")
for a in {100..$input..100}
#for a in {100..500..100}
do
    echo "Increment at $a times"
done

this will return:

"Increment at {100..200..100} times"

Will appreciate any help. Thank you!

Milky
  • 13
  • 3
  • Use `for ((a=100; a<= input; a+=100))`. Also, don't use `input=$(echo something)`, since the `echo` and the `$( )` basically cancel each other out; just use `input=something` instead. [shellcheck.net](https://www.shellcheck.net) is good at pointing out miskakes like these. – Gordon Davisson Apr 04 '22 at 05:16
  • Note that your assignment to `input` is unnecessary complicated. You can simplifiy it to `((input=2*100))`. Furthermore, you can't use parameter expansion inside range expressions, because bash expands range expressions before doing parameter expansion. – user1934428 Apr 04 '22 at 09:27

0 Answers0