Linux command to repeat a string n times
adrian@Fourier:~$ printf 'HelloWorld\n%.0s' {1..5}
HelloWorld
HelloWorld
HelloWorld
HelloWorld
HelloWorld
adrian@Fourier:~$
Here's an old-fashioned way that's pretty portable:
yes "HelloWorld" | head -n 10
This is a more conventional version of Adrian Petrescu's answer using brace expansion:
for i in {1..5}
do
echo "HelloWorld"
done
That's equivalent to:
for i in 1 2 3 4 5
This is a little more concise and dynamic version of pike's answer:
printf -v spaces '%*s' 10 ''; printf '%s\n' ${spaces// /ten}
Quite a few good ways already mentioned. Can't forget about good old seq
though:
[john@awesome]$for i in `seq 5`; do echo "Hi";done Hi Hi Hi Hi Hi