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]
[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"
-e: This option enables the interpretation of escape sequences in the given string.
echo -e "Line 1\nLine 2\tTabbed text."
Line 2 Tabbed text.
Echo Command options
|-n||Prevents the trailing newline character from being printed|
|-e||Enables interpretation of escape sequences in the string|
|-E||Disables interpretation of escape sequences|
|-c||Suppresses the trailing newline character (combined with -n)|
2. echo to evaluate shell variables
echo "My name is $name"
My name is Ram
It is used to display message on terminal