Portable to all shells and any system that has seq (as this questions is tagged)
If start is 1:
$ echo $(seq 10)
1 2 3 4 5 6 7 8 9 10
Otherwise:
$ echo $(seq 5 10)
5 6 7 8 9 10
With bc:
$ echo $(echo "for (i=0;i<=1000;i++) i"| bc)
In bash
echo {1..10}
Note:
This echo solution works if the value of IFS contains a newline, which it does by default.
By default IFS is set to the sequence <space><tab><newline>. And is reset for each clean start of the shell. But, if you have any concern that it may have changed in some extreme corner case, we have several solutions.
Under bash, zsh, ksh just use: IFS=$' \t\n' (skip all the rest of this answer).
However, resetting the value of IFS under sh may be complex Read the complete detail here.
Unset IFS.
$ unset IFS; echo $(seq 5 10) #Always work.
will always work. Provided that there will be no code below (or child scripts) that need IFS set, such as a script which does OldIFS="$IFS"
.
Correct solution.
Using a trick for sh:
sh -c 'IFS="$(printf " \t\nx")"; IFS="${IFS%x}"; printf "$IFS"|xxd' # correct.
echo $(seq 1 10)
– user3188445 Jul 26 '15 at 20:07