linux 中 printf函数常用选项设置占位长度、左对齐、输出百分号

 

001、设置占位长度

[root@pc1 test1]# printf "%s\n" "abc"                  ## 一般输出
abc
[root@pc1 test1]# printf "%20s\n" "abc"                ## 设置占位长度20,默认情况下是右对齐
                 abc
[root@pc1 test1]# printf "%-20s\n" "abc"               ## 设置占位长度20,并且利用-设置为左对齐
abc
[root@pc1 test1]# printf "%-20s\n" "abc" | cat -A      ## 查看隐藏的占位长度
abc                 $

 

002、 输出百分号

[root@pc1 test1]# printf "%%\n"        ## 输出百分号,需要用两个连续的%
%

 。

 

posted @ 2024-02-27 10:04  小鲨鱼2018  阅读(108)  评论(0)    收藏  举报