Echo Command - Writing Output on Screen


Echo Command


Echo is a shell built-in command used to display a line of text on standard output.

echo with -e option enables interpretation of backslash escapes

Some backslashes used for different purpose are:


\\
backslash
\a
alert (BEL)
\b
backspace
\c
suppress trailing newline
\f
form feed
\n
new line
\r
carriage return
\t
horizontal tab
\v
vertical tab





Examples of echo command


$ echo Hello world

Hello world



$ echo “Hello world”

Hello world


$ x=5

$ echo “The number is $x”

The number is 5



Printing home directory

$ echo ~

/home/user1


Printing all files and directories present in current directory.

$ echo *

It lists all files and directories.

Wild card expansion can be used with echo

$ echo D*

It shows file or Directory name start with D


$ echo Count_{1..5}

Count_1 Count_2 Count_3 Count_4 Count_5


$ echo Number_{1,3,5}

Number_1 Number_3 Number_5



Print username

$ echo $USER

It will show the name of user login.

No comments: