0

I wrote this bash script

x=64
y=1
ans=$((x-y))
z=`expr $ans`
for i in {1..$z}
do 
    echo $i
done

Actually, I would like to print i values from 1 to 63, 63 which is first obtained from the above addition. But it just prints {1..63}

Can someone please help me. Thanks in advance.

Socowi
  • 25,550
  • 3
  • 32
  • 54
rogwar
  • 143
  • 1
  • 1
  • 8
  • 5
    **Please don't answer this question. This is a 1:1 duplicate** of [How do I iterate over a range of numbers defined by variables in Bash?](https://stackoverflow.com/questions/169511/how-do-i-iterate-over-a-range-of-numbers-defined-by-variables-in-bash). Which has been asked over and over again. – Socowi Mar 13 '19 at 10:30
  • 1
    What are you trying to do with ``z=`expr $ans` ``? `z=$((x-y))` or just `((z=x-y))` is sufficient. – Socowi Mar 13 '19 at 10:32

2 Answers2

0

You're best of using a C-style for loop:

for ((n=$y; n<$x; n++)); do
    echo $n
done
Robert Seaman
  • 2,432
  • 15
  • 18
0

using seq :

for i in $(seq 1 $z) 
do 
   echo $i 
done
nullPointer
  • 4,419
  • 1
  • 15
  • 27