问题
I have a variable : str='abc'
I would like to copy it n times, with a space between each string, so the echo
gives, for n=3 :
echo $str
abc abc abc
I don't want a space after the last abc
I've already seen the link mentionned but they doesn't help. The last answer from @Amadan is the good one thanks, but I can't accept it :/
回答1:
One more way:
eval echo {1..$n} | sed "s/[[:digit:]]*/${var}/g"
Example:
n=3
var=abc
eval echo {1..$n} | sed "s/[[:digit:]]*/${var}/g"
abc abc abc
来源:https://stackoverflow.com/questions/56835374/bash-duplicate-a-string-variable-n-times