Writing a bash for-loop with a variable top-end

后端 未结 3 1188
萌比男神i
萌比男神i 2021-01-04 01:00

I frequently write for-loops in bash with the well-known syntax:

for i in {1..10}  [...]

Now, I\'m trying to write one where the top is def

3条回答
  •  别那么骄傲
    2021-01-04 01:11

    You can use for loop like this to iterate with a variable $TOP:

    for ((i=1; i<=$TOP; i++))
    do
       echo $i
       # rest of your code
    done
    

提交回复
热议问题