当前位置:网站首页>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!
边栏推荐
- Introduction to R language
- Audio-AudioRecord create(一)
- Principle and application of single chip microcomputer - principle of parallel IO port
- 嵌入式工程师面试题3-硬件
- V79.01 Hongmeng kernel source code analysis (user mode locking) | how to use the fast lock futex (Part 1) | hundreds of blogs analyze the openharmony source code
- Advanced C language pointer (Part 2)
- 《单片机原理及应用》-片外拓展
- 电视机尺寸与观看距离
- Matlab tips (23) matrix analysis -- simulated annealing
- 个人装修笔记
猜你喜欢

3. Detailed explanation of Modbus communication protocol
![[untitled]](/img/40/560c597d53d27eff860644cd7c3030.png)
[untitled]

5mo3 UHI HII HII 17mn4 19Mn6 executive standard

Brief introduction to AES

《微机原理》—总线及其形成

Huawei machine test questions column subscription Guide

Intelligent water supply system solution

SPL Introduction (I)

MAVROS发送自定义话题消息给PX4

Li Kou 1358 -- number of substrings containing all three characters (double pointer)
随机推荐
NIO-零拷贝
截图小妙招
SPL Introduction (I)
Brief introduction to AES
Share 7 books I read in the first half of 2022
[Yu Yue education] Shandong Vocational College talking about railway reference materials
FreeRTOS学习简易笔记
Insert mathematical formula in MD document and mathematical formula in typora
How to recruit Taobao anchor suitable for your own store
内存大小端
How to use OKR as the leadership framework of marketing department
Foundation: 2 The essence of image
公网集群对讲+GPS可视追踪|助力物流行业智能化管理调度
Introduction to R language
Intelligent water supply system solution
C语言学生信息管理系统
What is the material of 16mo3 steel plate? What is the difference between 16mo3 and Q345R?
R语言观察日志(part24)--初始化设置
Yolov3, 4, 5 and 6 Summary of target detection
1. Connection between Jetson and camera