Alex Rivera | Logout

Creating string of repeated characters in shell script

Asked 2010-07-09T10:50:26.073
62

I need to generate a string of dots (.characters) as a variable.

I.e., in my Bash script, for input 15 I need to generate this string of length 15: ...............

I need to do so variably. I tried using this as a base (from Unix.com):

for i in {1..100};do printf "%s" "#";done;printf "\n"

But how do I get the 100 to be a variable?

Edit
Report

1 Answer

-1

When I have to create a string that contains $x repetitions of a known character with $x below a constant value, I use this idiom:

base='....................'
# 0 <= $x <= ${#base}
x=5
expr "x$base" : "x\(.\{$x\}\)"    # Will output '\n' too

Output:

.....
answered 2010-07-09T14:50:03.243

Your Answer