Print range of numbers

Hi

I am getting an argument which specifies the range of numbers. eg: 7-15

Is there a way that i can easily (avoiding loop) print the range of number between and including the specified above.

The above example should translate to 7,8,9,10,11,12,13,14,15

Hello tostay2003,

Please use code tags while using commands and codes in your post as per forum rules. Following may help you in same.

for i in {7..15..1}
do
echo "Value of i is $i"
done

Output will be as follows.

Value of i is 7
Value of i is 8
Value of i is 9
Value of i is 10
Value of i is 11
Value of i is 12
Value of i is 13
Value of i is 14
Value of i is 15

Thanks,
R. Singh

$ seq -s, 7 15

---------- Post updated at 05:40 PM ---------- Previous update was at 05:31 PM ----------

If you have the literal value 7-15 as basis and it's in a variable:

$ var=7-15
$ seq -s, `echo $var | tr '-' ' '`

With recent shells with brace expansion:

var=7-15
eval echo {${var/-/..}}
7 8 9 10 11 12 13 14 15

The usual caveats for using eval apply.

1 Like