echo (display text)

Displays the text or variables specified.

Format:    echo textstring
Examples:  echo Hello World
           echo $HOME

The first example displays Hello World on the screen. The second example displays the contents of the variable HOME. $ indicates that HOME is a variable. HOME contains the path to your home directory, so the second example displays the path to your home directory on the screen.

You can use some special characters with the echo command to format the output, shown in the first table below. The second table shows the most useful options for echo.

CharWhat It DoesExample
\aAlert (rings bell)echo \aerror
\bBackspaceecho \bHello
\cSuppress new lineecho $text_line\c
\fForm feedecho Hello World\f
\nStart a new lineecho Hello \nWorld ...

Get Spring Into Linux® now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.