开发者

Can I align variables in a string with echo and bash?

开发者 https://www.devze.com 2022-12-21 15:58 出处:网络
I want to do formatting using echo in shell scripting. Here is a small code snippet which is giving me the problem:

I want to do formatting using echo in shell scripting.

Here is a small code snippet which is giving me the problem:

echo -en "\rFileName    :   $filename   :    $index of $lines Completed"

The $filename 开发者_运维知识库is a string with varying length, and this is causing problem with formatting in the terminal. How can I overcome this?

Here's what I mean:

FileName :       a800_102 :    6 of 6 Completed
FileName :       ersf_1024    :    56 of 56 Completed

I would like to have a table format when I display it on the terminal.


Use printf:

printf "\rFileName : %20s : %8d of %8d Completed" $filename $index $lines
0

精彩评论

暂无评论...
验证码 换一张
取 消