echo Command Examples in Linux

The echo command is used to display a line of text on the terminal. You can also use the echo command to write text to a file by providing the string after the echo command and redirecting to the file.

Syntax

The syntax of the echo command is:

# echo {string}

echo Command Examples

1. To echo the string on std op device:

# echo "Hi there" 

2. To skip printing the trailing new line:

# echo -n "Hi There" 

3. To enable the interpretation of backslash escapes (****):

# echo -e "Hi\a There"
Operator Interpretation
\\ backslash
\a alert (BEL)
\b backspace
\c produce no further output
\e escape
\f form feed
\n new line
\r carriage return
\t horizontal tab
\v vertical tab
\0NNN byte with octal value NNN (1 to 3 digits)
\xHH byte with hexadecimal value HH (1 to 2 digits)

4. To disable interpretation of backslash escapes:

# echo -E "Hi\! There" 

5. To display the help:

# echo --help 

6. To display the version:

# echo --version 
Related Post