echo是Linux bash和C shell中最常用和最廣泛使用的內(nèi)置命令之一。
echo的語法:
echo[option(s)][string(s)]
1.輸入一行文本并顯示在標(biāo)準(zhǔn)輸出上
$echorumenzisacommunityofLinuxNerds
輸出以下文本:
rumenzisacommunityofLinuxNerds
2.聲明一個變量并打印它的值。例如:聲明一個變量x并分配其值 =10.
$x=10
打?。?/p>
$echoThevalueofvariablex=$x Thevalueofvariablex=10
Note:這-eLinux 中的選項(xiàng)充當(dāng)反斜杠轉(zhuǎn)義字符的解釋。
3.使用選項(xiàng)退格符和反斜杠解釋器-e,刪除中間的所有空格。
$echo-e"rumenzisacommunityofLinuxNerds" rumenzisacommunityofLinuxNerds
4.使用選項(xiàng) 和-e換行輸出。
$echo-e"rumenz is a community of Linux Nerds" rumenz is a community of Linux Nerds
5.使用選項(xiàng) 水平制表符和-e。
$echo-e"rumenz is a community of Linux Nerds" rumenzisacommunityofLinuxNerds
6.同時使用選項(xiàng) 和水平制表符
$echo-e" rumenz is a community of Linux Nerds" rumenz is a community of Linux Nerds
7.使用選項(xiàng)v垂直制表符和-e
$echo-e"vrumenzvisvavcommunityvofvLinuxvNerds" rumenz is a community of Linux Nerds
8.同時使用選項(xiàng) 和垂直制表符v。
$echo-e" vrumenz vis va vcommunity vof vLinux vNerds" rumenz is a community of Linux Nerds
Note:我們可以使用該選項(xiàng)兩次或根據(jù)需要多次將垂直制表符、水平制表符和新行間距加倍。
9.使用選項(xiàng) 和-e光標(biāo)移至行首,但不換行。
$echo-e"rumenz isacommunityofLinuxNerds" isacommunityofLinuxNerds
10.使用選項(xiàng)c和-e不換行輸出,c后面的字符不顯示。
$echo-e"rumenzisacommunitycofLinuxNerds" rumenzisacommunityrumenz@local:~$
11.使用-n不輸出末尾的換行符。
$echo-n"rumenzisacommunityofLinuxNerds" rumenzisacommunityofLinuxNerdsrumenz@local:~/Documents$
12.使用選項(xiàng)a帶有退格解釋器的警報返回-e要有聲音警報。
$echo-e"rumenzisacommunityofaLinuxNerds" rumenzisacommunityofLinuxNerds
Note:確保在發(fā)射前檢查音量鍵。
13.使用echo命令打印所有文件。
$echo* 103.odt103.pdf104.odt104.pdf105.odt105.pdf106.odt106.pdf107.odt107.pdf108a.odt108.odt108.pdf109.odt109.pdf110b.odt110.odt110.pdf111.odt111.pdf112.odt112.pdf113.odtlinux-headers-3.16.0-customkernel_1_amd64.deblinux-image-3.16.0-customkernel_1_amd64.debnetwork.jpeg
14.打印所有.jpeg文件,請使用以下命令。
$echo*.jpeg network.jpeg
15.echo可以與重定向運(yùn)算符一起使用以輸出到文件而不是標(biāo)準(zhǔn)輸出。
$echo"rumenz.com">1.txt rumenz@local:~$cat1.txt rumenz.com
echo選項(xiàng)
Options | Description |
---|---|
-n | do not print the trailing newline. |
-e | enable interpretation of backslash escapes. |
backspace | |
backslash | |
new line | |
carriage return | |
horizontal tab | |
v | vertical tab |
審核編輯:劉清
-
Linux系統(tǒng)
+關(guān)注
關(guān)注
4文章
596瀏覽量
27524 -
ECHO
+關(guān)注
關(guān)注
1文章
73瀏覽量
27231 -
Shell
+關(guān)注
關(guān)注
1文章
366瀏覽量
23473
原文標(biāo)題:Linux中echo命令的15個實(shí)際示例
文章出處:【微信號:良許Linux,微信公眾號:良許Linux】歡迎添加關(guān)注!文章轉(zhuǎn)載請注明出處。
發(fā)布評論請先 登錄
相關(guān)推薦
shell基本介紹及常用命令之shell介紹
Linux用戶管理最常用的幾個命令
Linux Shell系列教程之Shell簡介和類型
Linux bash命令
最常用的Linux命令盤點(diǎn)
Linux之bash的主要介紹
linux shell命令/unix shell命令教程
![<b class='flag-5'>linux</b> <b class='flag-5'>shell</b><b class='flag-5'>命令</b>/unix <b class='flag-5'>shell</b><b class='flag-5'>命令</b>教程](https://file.elecfans.com/web2/M00/48/8A/pYYBAGKhtAyACPhpAABPbzxvkQo242.jpg)
Linux操作系統(tǒng)基礎(chǔ)命令:如何運(yùn)用Bash history
每個Linux用戶都需要知道的重要Bash shell變量
BASH shell腳本篇—條件命令
![<b class='flag-5'>BASH</b> <b class='flag-5'>shell</b>腳本篇—條件<b class='flag-5'>命令</b>](https://file1.elecfans.com/web2/M00/A7/B4/wKgaomUmTNGAWilRAALFOlU78M4291.jpg)
評論