Back to the command reference

echo

ShellBeginner In simulator In real Linux

Print a line of text

Name: echo: echoes its arguments back

You can practise it right away in the simulator, and use it in real Linux mode too.

Description

echo prints its arguments separated by spaces, followed by a newline. bash has a builtin echo and there is also /usr/bin/echo.

Implementations differ in how they treat -e and escape sequences; when exact formatting matters, prefer printf.

Syntax

echo [OPTION]... [STRING]...

Common options

-nDo not print the trailing newline
-eInterpret escapes such as \n and \t
-EDo not interpret backslash escapes (the default)

Examples

  • $ echo "Hello, $USER"

    Print text; variables inside double quotes are expanded

    Explain
  • $ echo "new line" >> documents/notes.txt

    Append a line to a file

    Explain
  • $ echo -e "a\tb"

    Print a tab character

    Explain

Related