practical examples of ' echo ' command in Linux
by Avishek Kumar Under:linux Commands on:august 21, 2014 translation by Smallliu
The echo command is the most commonly used built-in command for bash shells and C shells in Linux, most typically in scripts and batch files. The effect is to display a line of text in standard output or in a file.
echo Command Examples
The syntax form of the echo command is as follows:
echo [option (s)] [string (s)]
1. Enter a line of text and display it in standard output
The output results are as follows:
2. Declare a variable and get its value through ECHO. For example, the following is declaring an X variable and assigning its value to 10.
$ x=10
Get its value through the echo command:
$ echo the value of variable x = $x
Note: '-e ' option to treat escape characters as special
3. Use the ' \b ' option to remove the previous character from the \b
$ echo-e "Tecmint \bis \ba \bcommunity \bof" \blinux "
4. Using the ' \ n ' option will result in new line wrapping
$ echo-e "Tecmint \nis \na \ncommunity \nof \nlinux \nnerds"
tecmint
is
a
community
of
Linux
5. Using ' \ t ' will produce a tab
$ echo-e "Tecmint \tis \ta \tcommunity \tof \tlinux \tnerds"
tecmint is a community of Linux
6. The results of the use of both \ n and T are as follows:
$ echo-e "\n\ttecmint \n\tis \n\ta \n\tcommunity \n\tof \n\tlinux \n\tnerds"
tecmint
is
a
community< C11/>of
Linux
7. ' \v ' option, change line but the cursor still stays where it belongs
$ echo-e "\vtecmint \vis \va \vcommunity \vof \vlinux \vnerds"
tecmint
is
a
community
of
Linux
Nerds
8. ' \ n ' and ' \v ' options will produce two line break
$ echo-e "\n\vtecmint \n\vis \n\va \n\vcommunity \n\vof \n\vlinux \n\vnerds"
tecmint
is
a
community
of
Linux
9. ' \ r ' option, the text before this option is ignored.
$ ECHO-E "Tecmint \ris a community of Linux nerds"
The ' \c ' option ignores the text after \c and does not output a newline
$ ECHO-E "Tecmint is a community \cof Linux nerds"
One. '-n ' option to output text without output line wrapping
$ echo-n "Tecmint is a community of Linux nerds"
12. Use the ' \a ' option to issue a warning
$ Echo-e ' Tecmint is a community of \alinux nerds '
Tecmint is a community of Linux nerds
13. Show All files and folders
$ 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. Display files in the specified format
$ echo *.jpeg
network.jpeg
15. Redirect echo Echoes to testpage files
$ echo "Test page" > Testpage
# Check Content
avi@tecmint:~$ cat testpage
Test page
echo Command Options
Options |
Description |
-N |
Do not print the trailing newline.//output does not wrap |
-E |
Enable interpretation of backslash escapes.//interpreting escape characters |
\b |
BACKSPACE//Delete previous character |
\\ |
Backslash insert \ Character |
\ n |
New Line//newline character |
\ r |
Carriage return//cursor to First line |
\ t |
Horizontal tab//tab |
\v |
Vertical tab//NewLine cursor position unchanged |
Above that is all about echo content, what questions and comments please feedback in the comment column.