In Python strings can be "multiplied" to repeat them a number of times:
test="----"
print(test)
test="----"*10
print(test)
#output
----
----------------------------------------
Is there an equivalent in bash? I tried * but it doesn't work:
$ Test2="----"
$ echo $Test2
----
$ echo ${Test2}*5
----*5
$ echo $Test2*5
----*5
$ echo echo $[Test2]*5
-bash: ----: syntax error: operand expected (error token is "-")
$ echo $(Test2)*5
Test2: command not found
There's no equivalent shorthand, no. You can do it with an explicit loop like so:
test=""
for ((i=0; i<5; i++)); do test+="----"; done
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With