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.
1 | 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.
1 | echo -n "Hello" |
1 | Hello |
-e
: This option enables the interpretation of escape sequences in the given string.
1 | echo -e "Line 1\nLine 2\tTabbed text." |
1 2 | Line 1 Line 2 Tabbed text. |
Echo Command options
Option | Description |
---|---|
-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
1 2 | name="Ram" echo "My name is $name" |
1 | My name is Ram |
What does the echo command do
It is used to display message on terminal
Read More