I have the following string in bash
str="kallel"
I want to create from str
an str2
. The str2
contains str
duplicated till the length = 20. So the result should be like this:
str2="kallelkallelkallelka"
How to do in in bash?
I have the following string in bash
str="kallel"
I want to create from str
an str2
. The str2
contains str
duplicated till the length = 20. So the result should be like this:
str2="kallelkallelkallelka"
How to do in in bash?
This should work:
I am 100% stealing this answer from Bash : Duplicate a string variable n times but I thought it bore repeating (despite being on a 6 year old question):
I'd go for a while loop personally then cut it at the end.
While the length of
str2
is less than 20, addstr
tostr2
. Then, for good measure, we cut at the end to max 20 characters.