15 Praktesch Beispiller vum 'Echo' Kommando am Linux


Den Echo Kommando ass ee vun de meescht benotzt a verbreet agebaute Kommandoen fir Linux Bash a C Shells, déi typesch an enger Skriptsprooch a Batchdateien benotzt ginn fir eng Zeil vun Text/String op Standardausgang oder enger Datei ze weisen.

D'Syntax fir den Echo Kommando ass:

echo [option(s)] [string(s)]

1. Gitt eng Zeil vun Text a weist et op Standardausgang

$ echo Tecmint is a community of Linux Nerds 

Gitt de folgenden Text eraus:

Tecmint is a community of Linux Nerds 

2. Deklaréiert eng Variabel an echo säi Wäert. Zum Beispill, Deklaréiert eng Variabel vun x a gitt säi Wäert = 10.

$ x=10

echo säi Wäert:

$ echo The value of variable x = $x 

The value of variable x = 10 

Bemierkung: D'Optioun '-e' am Linux handelt als Interpretatioun vun entkomm Zeechen, déi zréckgeschnidde sinn.

3. Benotzt d'Optioun '' - Backspace mam Backslash Interpreter '-e' deen all d'Plazen tëscht läscht.

$ echo -e "Tecmint \bis \ba \bcommunity \bof \bLinux \bNerds" 

TecmintisacommunityofLinuxNerds 

4. Benotzt Optioun ' ' - Nei Linn mam Backspace Interpreter '-e' behandelt nei Linn vu wou se benotzt gëtt.

$ echo -e "Tecmint \nis \na \ncommunity \nof \nLinux \nNerds" 

Tecmint 
is 
a 
community 
of 
Linux 
Nerds 

5. Benotzt d'Optioun '' - horizontal Tab mat Backspace Interpreter '-e' fir horizontal Tabplazen ze hunn.

$ echo -e "Tecmint \tis \ta \tcommunity \tof \tLinux \tNerds" 

Tecmint 	is 	a 	community 	of 	Linux 	Nerds 

6. Wéi wier et mat der Optioun nei Linn ' ' an horizontal Tab '' gläichzäiteg.

$ echo -e "\n\tTecmint \n\tis \n\ta \n\tcommunity \n\tof \n\tLinux \n\tNerds" 

	Tecmint 
	is 
	a 
	community 
	of 
	Linux 
	Nerds 

7. Benotzt d'Optioun '' - vertikalen Tab mat Backspace Interpreter '-e' fir vertikal Tabplazen ze hunn.

$ echo -e "\vTecmint \vis \va \vcommunity \vof \vLinux \vNerds" 

Tecmint 
        is 
           a 
             community 
                       of 
                          Linux 
                                Nerds 

8. Wéi wier et mat der Optioun nei Linn ' ' a vertikalen Tab '' gläichzäiteg.

$ echo -e "\n\vTecmint \n\vis \n\va \n\vcommunity \n\vof \n\vLinux \n\vNerds" 


Tecmint 

is 

a 

community 

of 

Linux 

Nerds 

Notiz: Mir kënnen d'Vertikal Tab, d'horizontale Tab an d'nei Zeilenabstand verduebelen andeems Dir d'Optioun zweemol oder esou oft wéi néideg benotzt.

9. Benotzt Optioun ' ' - Carriage Retour mam Backspace Interpreter '-e' fir de Carriage Retour am Ausgang spezifizéiert ze hunn.

$ echo -e "Tecmint \ris a community of Linux Nerds" 

is a community of Linux Nerds 

10. Benotzt Optioun & # 8216

$ echo -e "Tecmint is a community \cof Linux Nerds" 

Tecmint is a community [email :~$ 

11. Verloossen echoing vun der neier Linn mat der Optioun '-n'.

$ echo -n "Tecmint is a community of Linux Nerds" 
Tecmint is a community of Linux [email :~/Documents$ 

12. Benotzt d'Optioun '' - Alarm zréck mam Backspace Interpreter '-e' fir den Tounalarm ze hunn.

$ echo -e "Tecmint is a community of \aLinux Nerds" 
Tecmint is a community of Linux Nerds

Bemierkung: Vergewëssert Iech de Volume Schlëssel ze kontrolléieren, ier Dir brennt.

13. Drécken all d'Dateien/Classeure benotzt Echo Kommando (ls Kommando Alternativ).

$ 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 

14. Drécken Dateien vun enger spezifescher Aart. Zum Beispill, loosst eis unhuelen datt Dir all '.jpeg' Dateien drécke wëllt, benotzt de folgende Kommando.

$ echo *.jpeg 

network.jpeg 

15. Den Echo kann mat engem Viruleedungsoperateur benotzt ginn fir op eng Datei erauszekréien an net Standardausgang.

$ echo "Test Page" > testpage 

## Check Content
[email :~$ cat testpage 
Test Page 

Dat ass alles fir elo a vergiesst net eis Äre wäertvolle Feedback an de Kommentarer hei drënner ze ginn.