Linux and Unix echo command tutorial with examples

The “echo” command in Unix is often used in the shell script for displaying/printing messages on the terminal.
There are two uses of the “echo” command.

  • “echo” is used for display/print messages on the terminal.
  • “echo” is also used to evaluate shell variables.

1. echo to print messages on the terminal.

Echo with options

-n: This option prevents the trailing newline character from being printed. It is useful when you want to display text without a newline at the end.

echo [OPTIONS] [STRING]

The [OPTIONS] are optional parameters that modify the behavior of the echo command, and the [STRING] is the text or variables to be displayed.

echo -n "Hello"
Hello

-e: This option enables the interpretation of escape sequences in the given string.

echo -e "Line 1\nLine 2\tTabbed text."
Line 1
Line 2    Tabbed text.

Echo Command options

OptionDescription
-nPrevents the trailing newline character from being printed
-eEnables interpretation of escape sequences in the string
-EDisables interpretation of escape sequences
-cSuppresses the trailing newline character (combined with -n)

2. echo to evaluate shell variables

name="Ram"
echo "My name is $name"
My name is Ram
What does the echo command do

It is used to display message on terminal

Read More

Unix Linux date command tutorial with examples