这篇文章主要介绍了linux shell中的printf的详细用法的相关资料,希望能通过本文能帮助到大家,需要的朋友可以参考下
Linux shell中的printf的详细用法
一 语法
printf '输出类型输出格式' 输出内容
输出类型:
%ns:输出字符串。n是数字指代输出几个字符。
%ni:输出整数。n是数字指代输出几个数字。
%m.n:输出浮点数。m和n是数字,指代输出的整数位数和小数
如%8.2代表共输出8位数,其中2位是小数,6位是整数。
输出格式:
二 实战
[root@localhost ~]# printf %s 1 2 3 4 5 6 123456[root@localhost ~]# printf %s %s %s 1 2 3 4 5 6 %s%s123456[root@localhost ~]# printf '%s %s %s' 1 2 3 4 5 6 1 2 34 5 6[root@localhost ~]# printf '%s\t%s\t%s\n' 1 2 3 4 5 6 1 2 3 4 5 6 [root@localhost ~]# printf '%s' $(cat student.txt) 1furongF852fengjF603cangF70[root@localhost ~]# [root@localhost ~]# printf '%s\t%s\t%s\t%s\n' $(cat student.txt) 1 furong F 85 2 fengj F 60 3 cang F 70
以上就是详细讲解Linux shell中的printf的用法的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号