2

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
John Kugelman
  • 349,597
  • 67
  • 533
  • 578

1 Answers1

2

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
John Kugelman
  • 349,597
  • 67
  • 533
  • 578