linux 终端使用 printf 命令

发布时间 2023-12-31 22:08:07作者: 小鲨鱼2018

 

001、输出字符串

[root@pc1 test1]# ls
[root@pc1 test1]# printf "hello world\n"        ## 方法一
hello world
[root@pc1 test1]# printf "%s\n" "hello world"   ## 方法二
hello world

 

002、输出整型

[root@pc1 test1]# ls
[root@pc1 test1]# printf "100\n"            ## 方法1
100
[root@pc1 test1]# printf "%d\n" 100         ## 方法2
100
[root@pc1 test1]# printf "%5d\n" 100        ## 指定宽度5
  100
[root@pc1 test1]# printf "%05d\n" 100       ## 指定宽度5,同时指定用0占位
00100

 

003、输出浮点型