print '*' * 80
This python snippet prints 80 asterisks, which I use often as delimiters in log files.
How can I do it in bash script using operator overloading?
print '*' * 80
This python snippet prints 80 asterisks, which I use often as delimiters in log files.
How can I do it in bash script using operator overloading?
In shell (ksh, zsh, bash) you can do:
stars=$(printf '%*s' 80 '')
echo "${stars// /*}"
With bash there's the option of doing:
printf -v stars '%*s' 80 ''
echo "${stars// /*}"
Explanation: The printf uses a format string %*s which means to produce a string of a length that is provided through an argument. So the first argument (80) specifies the length and the second argument specifies the string ('', an empty string) to be effectively printed, but blank-padded to the defined width. Note that this could also be expressed as printf "%80s" '', though I used the parameterized version for the length to make it explicit that it can be a variable parameter.