How to duplicate string in bash?

前端 未结 4 1946
臣服心动
臣服心动 2020-12-22 02:32

I have the following string in bash

str=\"kallel\"

I want to create from str an str2. The str2 conta

4条回答
  •  清酒与你
    2020-12-22 02:57

    I'd go for a while loop personally then cut it at the end.

    While the length of str2 is less than 20, add str to str2. Then, for good measure, we cut at the end to max 20 characters.

    #!/bin/bash
    str="kallel"
    str2=""
    while [ ${#str2} -le 20 ]
    do
        str2=$str2$str
    done
    str2=`echo $str2 | cut -c1-20`
    

提交回复
热议问题