2021年4月9日星期五

How to control the length of the line based on the length of the variable and be able to make the line uniform

I have the following function:

function separator_text() {      char="─"    text="${1}"    linelen="20"    filler=""      filler=$(printf "${char}%.0s" $(seq 1 "${linelen}"))      printf "%s%s%s" "${filler}" " ${text} " "${filler}"      printf "\n" # print new line    }    separator_text "normal text"  separator_text "short text"  separator_text "long text - long text"  

output:

─────────── normal text ───────────  ────────── short text ──────────  ──────────────────── long text - long text ────────────────────  

I want to control the length of the line based on the length of the variable and be able to make the line uniform.

someone could help me with this little problem.

Desired result:

─────────── normal text ───────────  ──────────── short text ───────────  ───── long text - long text ───────  
https://stackoverflow.com/questions/67029300/how-to-control-the-length-of-the-line-based-on-the-length-of-the-variable-and-be April 10, 2021 at 07:06AM

没有评论:

发表评论