How do I iterate over a range of numbers in Bash when the range is given by a variable?
I know I can do this (called \"sequence expression\" in the Bash documentatio
if you don't wanna use 'seq
' or 'eval
' or jot
or arithmetic expansion format eg. for ((i=1;i<=END;i++))
, or other loops eg. while
, and you don't wanna 'printf
' and happy to 'echo
' only, then this simple workaround might fit your budget:
a=1; b=5;
d='for i in {'$a'..'$b'}; do echo -n "$i"; done;'
echo "$d" | bash
PS: My bash doesn't have 'seq
' command anyway.
Tested on Mac OSX 10.6.8, Bash 3.2.48