shell使用echo打印输出及printf格式化输出
来源:互联网 发布:防arp攻击软件 编辑:程序博客网 时间:2024/05/17 07:58
shell 打印输出
shell主要有两种输出,echo,printf,格式化输出常常使用printf
1.echo
echo是很常用的打印输出命令:
如:
echoecho ' 'echo 'hello'echo "hello"
值得注意的是单引号(’)与双引号(“)略有区别
单引号直接输出后面的字符串,而双引号可以引入变量
例如:
[root@mytest ~]# str='string'[root@mytest ~]# echo 'str'str[root@mytest ~]# echo '$str'$str[root@mytest ~]# echo "$str"string
echo也可以用分号直接衔接两个字符串:
如:
[root@mytest ~]# echo 'this is ',$strthis is ,string
有些特殊情况下,既要输出$符号,又需要输出变量,则需要转移字符\
[root@mytest ~]# echo "this is \$str is $str"this is $str is string
另外:
echo很特殊的一个作用是可以彩色输出:
-e参数
2.printf
printf与c语言的基本一致
例如:
[root@mytest ~]# printf 'hello\n'hello
printf另外一个很重要的特点是,可以格式化输出,使显示结果相对工整
例如:
[root@mytest ~]# printf "ID: %-5s NAME: %-20s Avage: %4.2f\n" 1 tom 74.23333;printf "ID: %-5s NAME: %-20s Avage: %4.2f\n" 5 jack 81.66666;printf "ID: %-5s NAME: %-20s Avage: %4.2f\n" 3 stve 78.50000ID: 1 NAME: tom Avage: 74.23ID: 5 NAME: jack Avage: 81.67ID: 3 NAME: stve Avage: 78.50
0 0
- shell使用echo打印输出及printf格式化输出
- awk字符串函数(printf格式化输出) -- shell
- shell printf命令:格式化输出语句
- shell printf命令:格式化输出语句
- (9)shell printf命令:格式化输出
- shell printf命令:格式化输出语句
- shell printf命令:格式化输出语句
- shell printf命令:格式化输出语句
- shell printf命令:格式化输出语句
- shell printf命令:格式化输出语句
- shell printf命令:格式化输出语句
- shell printf命令:格式化输出语句
- 十、shell printf命令:(格式化输出语句)
- Linu Shell 编程基础--变量,简单的输出,echo,printf
- Shell打印echo和printf
- printf函数格式化输出使用总结
- printf 格式化输出
- printf 格式化输出
- Robot Framework
- Struts(2)Struts快速入门案例和使用filter配合Struts,解决中文乱码问题
- angular表单验证笔记篇
- EasyUI——datagrid 的onLoadSuccess事件无数据时提示
- springboot 集成mybatis
- shell使用echo打印输出及printf格式化输出
- DP——Maximum Subarray
- mysql源码学习笔记:文件读写模块IO_CACHE
- 使用Jquery解析Json基础知识
- 当你无助时,你会想起谁?
- 使用Disqus API实现"最近评论"功能
- 二维数组的几种表示方法
- Remove Duplicates from Sorted Array
- SDKD2017——Scarily interesting! (贪心)