Home » linux » Linux and Unix echo command tutorial with examples

Linux and Unix echo command tutorial with examples

“echo” command in Unix often used in the shell script for display/print message on the terminal.
There are two uses of “echo” command.

  • “echo” is used for display/print message on terminal.
  • “echo” is also used for evaluate shell variable.

“echo” is used for display/print message on terminal

To print the message on terminal press echo command on terminal and message to print place within “ “ double quote as shown below.

output

Escape sequence: “echo” command interprets certain string as a escape sequence.
The escape sequence is generally (not necessarily ) a two character string which starts with a backslash ( \ ).
For example: “ \c “ is a one escape sequence and if we place “ \c ” escape sequence at the end of the line/string then this escape sequence place the cursor on the same line that displays the output.

output

Note: echo escape sequence are the feature of VSBD system. Linux Bash shell, the standard shell used in Linux interprets escape sequence if echo command is used with “–e” option

Other Escape sequences:

Sr NoEscape SequenceMeaning
1\a

Bell
2\bBackspace
3\cNo new line
4\n
New line
5\t

Tab
6\vVertical Tab

“echo” is also used to evaluate shell variable.
Assign value to variable : we can assign a value to variable on terminal as

output

Note: When we assign a value to a variable must remember there is no space either side of = sign.

Evaluate the value of a variable: to evaluate the value of variable write “echo” then place $ sign before variable as shown below:

output

Managed by MochaHost - Fast & Easy WordPress Hosting