仿C程序的printf()程序
printf format-string [arguments...]
format-string用双引号或单引号括起来,如果只有1个输出可不用引号
printf需手动添加\n才能起到换行效果。echo会自动添加换行符。
%-ns:宽度为n个字符,-左对齐,否则右对齐,不足用空格,超过全部显示
%m.nf:整数m位,小数n位。
%d:整数
无对应参数%s为NULL, %d为0
eg:
[root@k8s-master test3]# echo "helloworld"
helloworld
[root@k8s-master test3]# printf "helloworld"
helloworld[root@k8s-master test3]# printf "helloworld\n"
helloworld
[root@k8s-master test3]#
[root@k8s-master test5]# ./t0.sh
name sex height
tom male 160.33
jack female 178.999
[root@k8s-master test5]# cat t0.sh
#!/bin/bash
printf "%-15s %-8s %-5s\n" name sex height
printf "%-15s %-8s %-5.2f\n" tom male 160.333
printf "%-15s %-8s %-5.3f\n" jack female 178.999
[root@k8s-master test5]#