BigSecrect BigSecrect - 7 months ago 16
Bash Question

Generate a range of numbers using shell script

I need to generate a range of numbers with a fixed interval. I need to display them exactly as shown below.

Starting from 1 and end at 200, the interval is 50.

Two numbers in each row, a space between numbers, arranged this way....

1 50
51 100
101 150
151 200

Answer

using bash:

for (( i = 1; i < 200; i += 50 )); do echo $i $(( $i+49 )); done

$(( )) is for arithmetic expansion.

for (( ; ; )) is the compound command that resemble the C for syntax.

Comments