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 @   小鲨鱼2018  阅读(89)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
历史上的今天:
2023-02-27 centos7中 /lib/ld-linux.so.2: bad ELF interpreter: No such file or directory
2023-02-27 Error downloading packages: glibc-2.17-326.el7_9.i686: [Errno 5]
2023-02-27 win10 中tassel5安装后字体特别小的解决方法
2023-02-27 centos 7中 出现 bash: pip: command not found...解决方法
2023-02-27 SyntaxError: Non-ASCII character '\xe8' in file test.py on line 6,
2022-02-27 could not find function "get_geo_position"
点击右上角即可分享
微信分享提示