Note Of course, there are more elegant ways to do this, like Ben Grimm's answer, and this is not purely bash since it uses seq and awk.
One way to achieve this is by calling seq . It would be trivial if you knew the numbers in the string beforehand, so there was no need to do any conversion, since you could just do seq 1 4 or seq $a $b , for that matter.
I assume, however, that your input is indeed a string in the format you specify, i.e. 20..100 or 20..100 . To do this, you can convert the string to 2 numbers and use them as parameters for seq .
One possible way to achieve this:
$ `echo "1..4" | sed -e 's/\.\./ /g' | awk '{print "seq", $1, $2}'` 1 2 3 4
Note that this will work the same for any input in this format. If desired, sed can be changed to tr with similar results.
$ x="10..15" $ `echo $x | tr "." " " | awk '{print "seq", $1, $2}'` 10 11 12 13 14 15
source share