来自公众号:入门小站 链接:https://rumenz.com/rumenbiji/linux-base-echo.html
echo
是Linux bash和C shell中最常用和最广泛使用的内置命令之一。
echo的语法:
echo [option(s)] [string(s)]
$ echo rumenz is a community of Linux Nerds
输出以下文本:
rumenz is a community of Linux Nerds
x
并分配其值 =10
.$ x=10
打印:
$ echo The value of variable x = $x The value of variable x = 10
Note
:这 -e
Linux 中的选项充当反斜杠转义字符的解释。
\b
退格符和反斜杠解释器-e
,删除中间的所有空格。$ echo -e "rumenz \bis \ba \bcommunity \bof \bLinux \bNerds" rumenzisacommunityofLinuxNerds
\n
和-e
换行输出。$ echo -e "rumenz \nis \na \ncommunity \nof \nLinux \nNerds" rumenz
is
a
community
of
Linux
Nerds
\t
水平制表符和-e
。$ echo -e "rumenz \tis \ta \tcommunity \tof \tLinux \tNerds" rumenz is a community of Linux Nerds
\n
和水平制表符\t
$ echo -e "\n\trumenz \n\tis \n\ta \n\tcommunity \n\tof \n\tLinux \n\tNerds" rumenz
is
a
community
of
Linux
Nerds
\v
垂直制表符和-e
$ echo -e "\vrumenz \vis \va \vcommunity \vof \vLinux \vNerds" rumenz
is
a
community
of
Linux
Nerds
\n
和垂直制表符\v
。$ echo -e "\n\vrumenz \n\vis \n\va \n\vcommunity \n\vof \n\vLinux \n\vNerds" rumenz
is
a
community
of
Linux
Nerds
Note
:我们可以使用该选项两次或根据需要多次将垂直制表符、水平制表符和新行间距加倍。
\r
和-e
光标移至行首,但不换行。$ echo -e "rumenz \ris a community of Linux Nerds" is a community of Linux Nerds
\c
和-e
不换行输出,\c
后面的字符不显示。$ echo -e "rumenz is a community \cof Linux Nerds" rumenz is a community [email protected]local:~$
-n
不输出末尾的换行符。$ echo -n "rumenz is a community of Linux Nerds"
rumenz is a community of Linux [email protected]local:~/Documents$
\a
带有退格解释器的警报返回-e
要有声音警报。$ echo -e "rumenz is a community of \aLinux Nerds"
rumenz is a community of Linux Nerds
Note
:确保在发射前检查音量键。
$ echo * 103.odt 103.pdf 104.odt 104.pdf 105.odt 105.pdf 106.odt 106.pdf 107.odt 107.pdf 108a.odt 108.odt 108.pdf 109.odt 109.pdf 110b.odt 110.odt 110.pdf 111.odt 111.pdf 112.odt 112.pdf 113.odt linux-headers-3.16.0-customkernel_1_amd64.deb linux-image-3.16.0-customkernel_1_amd64.deb network.jpeg
.jpeg
文件,请使用以下命令。$ echo *.jpeg network.jpeg
$ echo "rumenz.com" > 1.txt [email protected]local:~$ cat 1.txt
rumenz.com
echo
选项Options | Description |
---|---|
-n | do not print the trailing newline. |
-e | enable interpretation of backslash escapes. |
\b | backspace |
\ | backslash |
\n | new line |
\r | carriage return |
\t | horizontal tab |
\v | vertical tab |
---END---