Usage
# Print a text message. Note: quotes are optional:
$ echo "Hello World"
# Print a message with environment variables:
$ echo "My path is $PATH"
# Append a message to the file:
$ echo "Hello World" >> file.txt
# Enable interpretation of backslash escapes (special characters):
$ echo -e "Column 1\tColumn 2"
常用转义字符
-
\b
:转义后相当于按退格键(backspace) ,但前提是"\b"后面存在字符 -
\c
:不换行输出,在"\c"后面不存在字符的情况下,作用相当于echo -n -
\n
:换行$ echo "Hello World\n" Hello World
-
\f
:换行,但是换行后的新行的开头位置连接着上一行的行尾 -
\v 与\f相同
-
\t
:插入tab,即制表符$ echo "Hello\tWorld" Hello World
-
\r 光标移至行首,但不换行,相当于使用"\r"以后的字符覆盖"\r"之前同等长度的字符:
$ echo "Hello World\rWei" Weilo World
-
\\
:表示插入""本身$ echo "Hello\\World" Hello\World
-n
- 输出结尾不换行
# Print a message without the trailing newline
$ echo -n "Hello World"
Reference
- man echo
FEATURED TAGS
algorithm
algorithmproblem
architecturalpattern
architecture
aws
c#
cachesystem
codis
compile
concurrentcontrol
database
dataformat
datastructure
debug
design
designpattern
distributedsystem
django
docker
domain
engineering
freebsd
git
golang
grafana
hackintosh
hadoop
hardware
hexo
http
hugo
ios
iot
java
javaee
javascript
kafka
kubernetes
linux
linuxcommand
linuxio
lock
macos
markdown
microservices
mysql
nas
network
networkprogramming
nginx
node.js
npm
oop
openwrt
operatingsystem
padavan
performance
programming
prometheus
protobuf
python
redis
router
security
shell
software testing
spring
sql
systemdesign
truenas
ubuntu
vmware
vpn
windows
wmware
wordpress
xml
zookeeper