You can abuse printf for that:
printf '\n%.s' {1..100}
This prints \n
followed by a zero-length string 100 times (so effectively, \n
100 times).
One caveat of using brace expansion though is that you cannot use variables in it, unless you eval it:
count=100
eval "printf '\n%.s' {1..$count}"
To avoid the eval you can use a loop; it's slightly slower but shouldn't mater unless you need thousands of them:
count=100
for ((i=0; i<$count; i++)); do printf '\n'; done
NB: If you use the eval method, make sure you trust your count, else it's easy to inject commands into the shell:
$ count='1}; /bin/echo "Hello World ! " # '
$ eval "printf '\n%.s' {1..$count}"
Hello World !
One easy fix in Bash is to declare your variable as an integer (ex: declare -i count
). Any attempts to pass something else than an number will fail. It may still be possible to trigger DOS attacks by passing very large values for the brace expansion, which may cause bash to trigger an OOM condition.