shell 脚本之 printf
来源:互联网 发布:relief算法python实现 编辑:程序博客网 时间:2024/04/28 19:30
shell 脚本之printf
- 上篇转载了echo的用法,那么我们本篇就讲一下shell 脚本的格式化输出。shell 的printf基本上继承了 c语言的printf 函数的格式,你只要会c语言的printf 函数,那么shell 脚本的printf 函数对于你来说也没有什么难度。
参考了这篇博客:http://blog.csdn.net/shanyongxu/article/details/46744055
先上代码:
#! /bin/bashprintf "%-50s %-20s \n" first second #第一个字符串50个字符左对齐,第二个20个字符左对齐,\n 代表换行printf "%50s %20s \n" first second #默认右对齐printf "%4d %4d \n" 1234 12345 #输出整型printf "%s %s %s \n" a b c d e f g h i j #多个参数,每行输出三个字符printf "%s %s hello \n" first second #hello为在参数后输出的字符串printf "%04d %10.2f \n" 123 9 #不足部位,4 位整数不足补0,保留两位小数
最后看一下结果:
是不是很简单,那就自己动手做一下吧。
0 0
- shell 脚本之 printf
- shell脚本中printf小节
- shell脚本中printf小节
- shell脚本中printf小节
- shell脚本中printf小节
- shell脚本中printf小节
- shell脚本中printf小节
- shell 之 printf
- Shell 之echo printf
- shell脚本输出对齐问题(使用printf)
- Shell脚本入门(十六) - printf
- 脚本乐园 shell中printf用法
- shell 脚本echo和printf学习
- 脚本初步之echo & printf
- 【Shell脚本学习15】shell printf命令:格式化输出语句
- shell脚本之shell数组
- Shell脚本之循环
- shell脚本之gettop
- JS下拉框框多选问题
- 【Linux】-Ubuntu常用命令吐血整理
- win10锁屏图片该如何使用
- Java自定义异常
- as中建立和运行java程序
- shell 脚本之 printf
- Android Studio无法接真机调试问题
- http请求get请求和post请求的区别
- 规范代码
- Go文件操作大全
- 清除浮动
- iOS的横竖屏切换旋转(禁自动旋转)
- 关于IPTABLES 各种MARK 功能的用法
- scala类型系统:19) Manifest与TypeTag