Linux [Electronic resources]

Janet Valade

نسخه متنی -صفحه : 357/ 291
نمايش فراداده

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.

Char

What It Does

Example

\a

Alert (rings bell)

echo \aerror

\b

Backspace

echo \bHello

\c

Suppress new line

echo $text_line\c

\f

Form feed

echo Hello World\f

\n

Start a new line

echo Hello \nWorld

\r

Carriage return

echo Hello World\r

\t

Insert a tab

echo Hello \tWorld

\v

Insert a vertical tab

echo \vHello World

\\

Literal

echo This is a backslash \\

Opt

What It Does

Example

-n

Don't start a new line after text

echo -n Hello echo " World Hello World