Bash: 重复字符串

 

  1. 函数
    #!/bin/bash
    
    function b(){
        for i in `seq 1 $2`;do
            echo -n "$1"
        done
    }
    
    b = 1

     

  2. printf
    printf '=%.0s' {1..10}
    printf %10s | tr ' ' =

     

  3. seq tr 
    seq -s= 10 | tr -d '[:digit:]'

     

  4. for
    for b in {1..10}; do echo -n =;done

     

  5. head tr
    head --bytes 10 < /dev/zero | tr '\0' =

     

  6. paste
    yes = | head -10 | paste -s -d '' -

     

  7. {str// /repr}
    str=$(printf %10s)
    
    echo ${str// /@}

     

posted @ 2022-09-28 17:28  ascertain  阅读(115)  评论(0)    收藏  举报