'How to iterate in a range determined by TWO variables?
I have a code:
echo "the range's starting number:"
read -r a #it was 10
echo "the range's ending number:"
read -r b #it was 20
for (( c=$a; c<=$b; c++ ))
do
echo $c
done
Question: what is the working syntax? I found a similar question where c=1; c<=$b; c++ worked. I want to iterate between $a (example $a=10) and $b (example $b=20) and not between 1 and $b=20. Thanks for the help. (the output is blank here, the expected output was: 10 11 12 .. 20 I tried my code, also closed terminal and started a new one because of possible caching issues, but there was still a blank output. Update: in the comments accdias's answer was working. With for ((c=a; c<=b; c++)) i got the expected output. Thanks all for the help and comments!
Solution 1:[1]
I took @accdias's comment and figured I would just drop it here as an answer for easy reference:
START=12
END=24
for ((i=START; i<=END; i++)); do
echo $i
done
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Charley Bodkin |