当前位置:网站首页>Shell脚本-echo命令 转义符
Shell脚本-echo命令 转义符
2022-07-01 08:36:00 【小蜗牛的路】
echo 是一个 Shell 内建命令,用来在终端输出字符串,并在最后默认加上换行符。
输出不换行
echo 命令输出结束后默认会换行,如果不希望换行,可以加上-n参数,如下所示:
#!/bin/bash
name="Tom"
age=20
height=175
weight=62
echo -n "${name} is ${age} years old, "
echo -n "${height}cm in height "
echo "and ${weight}kg in weight."
echo "Thank you!"
输出:
Tom is 20 years old, 175cm in height and 62kg in weight.
Thank you!
输出转义字符
默认情况下,echo 不会解析以反斜杠\开头的转义字符。比如,\n表示换行,echo 默认会将它作为普通字符对待。请看下面的例子:
[[email protected] ~]# echo "hello \nworld"
hello \nworld
参数:-e
我们可以添加-e参数来让 echo 命令解析转义字符
[[email protected] ~]# echo -e "hello \nworld"
hello
world
转义字符:\c
有了-e参数,我们也可以使用转义字符\c来强制 echo 命令不换行了
#!/bin/bash
name="Tom"
age=20
height=175
weight=62
echo -e "${name} is ${age} years old, \c"
echo -e "${height}cm in height \c"
echo "and ${weight}kg in weight."
echo "Thank you!"
输出:
Tom is 20 years old, 175cm in height and 62kg in weight.
Thank you!
边栏推荐
- Advanced API
- Li Kou 1358 -- number of substrings containing all three characters (double pointer)
- 【MFC开发(17)】高级列表控件List Control
- SPL-安装与基本使用(二)
- 电视机尺寸与观看距离
- C语言学生信息管理系统
- Model and view of QT
- R语言观察日志(part24)--初始化设置
- 15Mo3 German standard steel plate 15Mo3 chemical composition 15Mo3 mechanical property analysis of Wuyang Steel Works
- 3、Modbus通讯协议详解
猜你喜欢

中小企业固定资产管理办法哪种好?

嵌入式工程师面试题3-硬件

Advanced C language pointer (Part 2)

《微机原理》——微处理器内部及外部结构

Introduction to R language

1.jetson与摄像头的对接

The data analyst will be ruined without project experience. These 8 project resources will not be taken away

Computer tips

What is the material of 16mo3 steel plate? What is the difference between 16mo3 and Q345R?

Memory size end
随机推荐
电视机尺寸与观看距离
任务、线程、进程 区别
《微机原理》—总线及其形成
The era of low threshold programmers is gone forever behind the sharp increase in the number of school recruitment for Internet companies
Introduction to 18mnmo4-5 steel plate executive standard and delivery status of 18mnmo4-5 steel plate, European standard steel plate 18mnmo4-5 fixed rolling
《单片机原理及应用》-片外拓展
Matlab tips (23) matrix analysis -- simulated annealing
Properties of 15MnNiNbDR low temperature vessel steel, Wugang 15MnNiDR and 15MnNiNbDR steel plates
VSYNC+三重缓存机制+Choreographer
内存大小端
《微机原理》-绪论
The meaning of yolov5 training visualization index
Insert mathematical formula in MD document and mathematical formula in typora
19Mn6 German standard pressure vessel steel plate 19Mn6 Wugang fixed binding 19Mn6 chemical composition
Glitch free clock switching technology
3、Modbus通讯协议详解
IT 技术电子书 收藏
中断与其他函数共享变量、临界资源的保护
Yolov3, 4, 5 and 6 Summary of target detection
[detailed explanation of Huawei machine test] judgment string subsequence [2022 Q1 Q2 | 200 points]