On Unix-like operating systems, the echo command prints text to standard output, e.g., the terminal.

This page covers the GNU/Linux version of echo.

Description

echo is a fundamental command found in most operating systems. It is frequently used in scripts, batch files, and as part of individual commands; anywhere you may need to output text.

  • Description

  • Syntax

  • Options

  • Options

  • Options

  • Escape sequences

  • Examples

  • Related commands

  • Linux commands help

  • Options

  • Options

  • Escape sequences

Most command shells, including bash, ksh and csh implement echo as a built-in command. The behavior of built-in echo commands is similar, but the options may be different; those commands are not documented here.

This page covers the stand-alone program, /bin/echo. Its options are slightly different than the built-in echo command that is included in your shell. If you are using the bash shell, you can determine which echo is the default, using the type command:

type echo

echo is a shell builtin

To specify that you want to run the stand-alone program instead of the shell built-in, use its complete path in the command, i.e., run it like this:

/bin/echo

This page describes the GNU/Linux stand-alone version of echo.

Syntax

echo [SHORT-OPTION]… [STRING]…

echo –help

echo –version

Options

Options

These options may be specified before the string, and affect the behavior of echo.

If a long option is specified, you may not specify a string to be echoed. These options are for getting information about the program only.

Escape sequences

If you specify the -e option, the following escape sequences are recognized in your string:

Examples

/bin/echo Hello, world!

In the above command, the two words (Hello, and world!) are passed to echo as separate arguments, and echo prints them in sequence, separated by a space:

Each shell generally has its own implementation of echo, which may be slightly different than the version described here. Refer to your shell’s documentation for details about the options it supports.

Hello, world!

The next command produces the same output:

/bin/echo ‘Hello, World!’

However, unlike the first example, the above command provides the single-quoted string ‘Hello, world!’ as a single argument.

Single-quoting a string will reliably protect it from interpretation by the shell, passing special characters and escape sequences literally to echo.

For instance, in the bash shell, variable names are preceded by a dollar sign ($). In the next command, the variable name inside the quotes is treated literally; outside the quotes, it is converted to its value.

/bin/echo ‘The value of $PATH is’ $PATH

The value of $PATH is /home/hope/bin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

Escape sequences are not interpreted, by default:

/bin/echo ‘Here, \bthe \bbackspace \bsequences \bare \bignored.’

Here, \bthe \bbackspace \bsequences \bare \bignored.

However, if you provide the -e option, they are interpreted:

/bin/echo -e ‘Here, \bhowever, \bthe \bbackspace \bsequences \bare \binterpreted.’

Here,however,thebackspacesequencesareinterpreted.

If you need to insert newlines in your echo output, specify the -e option and include the \n escape sequence wherever you want a new line:

echo -e ‘Here,\nwe\nhave\ninserted\nnewlines.’

Here, we have inserted newlines.

Same for tabs:

echo -e ‘Here\twe\thave\tinserted\thorizontal\ttabs.’

Here we have inserted horizontal tabs.

Another example:

echo -e ‘This line is not completely \cprinted.’

This line is not completely

cat — Output the contents of a file.printf — Write formatted output.tac — Output the contents of files in reverse order.tee — Route a file’s contents to multiple outputs.touch — Update the timestamp of a file or directory.tr — Translate one set of characters to another.