Skip to content

echo command

Print text and variables.

On this page

Syntax

echo [options] [text…]

Provided by the shell builtin / coreutils package. Run man echo for the full manual.

Common options

OptionWhat it does
-nNo newline at the end
-eInterpret escapes like \n and \t
-EDon't interpret escapes (default)

Examples

  1. Print text

    echo "Hello, world"
  2. Print a variable

    echo "Home is $HOME"
  3. No trailing newline

    echo -n "Enter name: "
  4. Escapes

    echo -e "Line 1\nLine 2"
  5. Write to a file

    echo "export EDITOR=vim" >> ~/.bashrc
  6. Print the last exit code

    echo $?

Tips

  • For exact formatting, printf is more portable than echo -e.

echo guides

← All Linux commands · Suggest a fix

Back to top