0

I am trying to set a variable that set the number of for loops in bash.

Hi, I am trying to set a variable that set the number of for loops in bash.

#!/bin/bash

num_loops=3
for i in {1.."$num_loops"}
do
 echo $i
done

However I got as output this:

{1..3}

Instead I would like this output:

1
2
3

I am not an expert in bash, but it ooks to me that the variable num_loops has become a string? Can someone explain me this? Thanks

  • 2
    This is [BashPitfalls #33](https://mywiki.wooledge.org/BashPitfalls#for_i_in_.7B1...24n.7D). Use a C-style for loop: `for ((i=0; i – Charles Duffy Nov 16 '22 at 18:09

0 Answers0