linux 终端使用 printf 命令
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、输出浮点型
[root@pc1 test1]# ls [root@pc1 test1]# printf "10.56\n" ## 方法1 10.56 [root@pc1 test1]# printf "%f\n" 10.56 ## 方法2 10.560000 [root@pc1 test1]# printf "%.1f\n" 10.56 ## 指定一位小数 10.6 [root@pc1 test1]# printf "%8.1f\n" 10.56 ## 指定宽度为8 10.6 [root@pc1 test1]# printf "%08.1f\n" 10.56 ## 用0占位 000010.6
004、科学计数法
[root@pc1 test1]# ls [root@pc1 test1]# printf "%e\n" 110400 ## 科学计数法 1.104000e+05 [root@pc1 test1]# printf "%8.2e\n" 110400 ## 两位小数 1.10e+05 [root@pc1 test1]# printf "%E\n" 110400 ## 同上 1.104000E+05 [root@pc1 test1]# printf "%8.2E\n" 110400 ## 同上 1.10E+05
。
分类:
linux shell
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
2022-12-31 linux 中wget命令的几个常用选项
2022-12-31 从NCBI中下载SRA数据
2022-12-31 linux 中对带有空格、括号的文件进行重命名
2022-12-31 linux 中删除文件名中的括号
2022-12-31 linux 中删除文件名中的空格
2022-12-31 linux中统计文本中每一行中空格的总数目
2022-12-31 linux 中实现文件名的补齐