当前位置:网站首页>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!
边栏推荐
- Internet of things technology is widely used to promote intelligent water automation management
- factory type_ Id:: create process resolution
- Audio-AudioRecord create(一)
- Do you know how data is stored? (C integer and floating point)
- 电视机尺寸与观看距离
- 长安链同步节点配置与启动
- Introduction to R language
- There are many problems in sewage treatment, and the automatic control system of pump station is solved in this way
- Mavros sends a custom topic message to Px4
- Qt的模型与视图
猜你喜欢

3. Detailed explanation of Modbus communication protocol

Advanced C language pointer (Part 2)

SPL installation and basic use (II)

Guidelines and principles of did

Glitch free clock switching technology

Internet of things technology is widely used to promote intelligent water automation management

TypeError: __init__() got an unexpected keyword argument ‘autocompletion‘

R语言入门

一文纵览主流 NFT 市场平台版税、服务费设计

【无标题】
随机推荐
电视机尺寸与观看距离
【C】 Summary of wrong questions in winter vacation
Review of week 280 of leetcode
The use of word in graduation thesis
What is 1cr0.5mo (H) material? 1cr0.5mo (H) tensile yield strength
IT 技术电子书 收藏
C语言学生信息管理系统
C语言指针的进阶(上篇)
基于Gazebo的无人机管道检测
Foundation: 2 The essence of image
[MFC development (17)] advanced list control list control
Internet of things technology is widely used to promote intelligent water automation management
I would like to know the process of stock registration and account opening by mobile phone? In addition, is it safe to open a mobile account?
Introduction to 18mnmo4-5 steel plate executive standard and delivery status of 18mnmo4-5 steel plate, European standard steel plate 18mnmo4-5 fixed rolling
Centos7 shell script one click installation of JDK, Mongo, Kafka, FTP, PostgreSQL, PostGIS, pgrouting
Redis publish subscription
明明设计的是高带宽,差点加工成开路?
Agrometeorological environment monitoring system
Nacos - 配置管理
分享2022上半年我读过的7本书