← Linux command list

echo command: print text and variable values

__ __ _ _____
\ \ / /__| |_|_ _|__ _ __ _ __ ___
\ \ /\ / / _ \ '_ \| |/ _ \ '__| '_ ` _ \
\ V V / __/ |_) | | __/ | | | | | |
\_/\_/ \___|_.__/|_|\___|_| |_| |_| |_
 
A sandbox for trying echo. Nothing here can touch your real files.
user@webterm:~/project$
 

echo prints whatever you hand it. Learn how to check what is inside an environment variable, when to use single or double quotes, and how `>` writes the text to a file, by running the commands in a real terminal in your browser.

Updated: 2026-09-06

Syntax

echo [options] string...

It prints the strings you pass, followed by a single newline.

Try it first

$ echo hello world
hello world

Arguments are split on spaces and printed back joined by one space each. That is why extra spaces collapse.

$ echo hello    world
hello world

Quote the text to keep it exactly as written.

$ echo "hello    world"
hello    world

Looking inside a variable

With $, the shell replaces the name with its value before echo ever sees it.

$ echo $HOME
/home/user
$ echo $PATH
/usr/bin:/bin:/usr/local/bin

This is the everyday use. It lets you confirm that a value you thought you set is really there, before you run the thing that depends on it.

Choosing your quotes

Inside double quotes a variable turns into its value. Inside single quotes it does not.

$ echo "deployed by $USER"
deployed by user
$ echo 'deployed by $USER'
deployed by $USER

Use single quotes when you want to show the $ text itself.

Writing to a file

> sends the text to a file instead of the screen.

$ echo build ok > result.txt
$ cat result.txt
build ok

>> adds to the end.

$ echo second line >> result.txt
$ cat result.txt
build ok
second line

> overwrites. Point it at the same file again and whatever was there is gone.

$ echo overwritten > result.txt
$ cat result.txt
overwritten

Tabs, newlines and no newline

-e makes escapes such as \t and \n mean tab and newline.

$ echo -e "name\tstatus"
name	status

-n leaves off the final newline.

$ echo -n done
done

When you actually reach for it

echo is what you type to check something and to add a single line.

SituationWhat to type
Check that an environment variable is setecho $DATABASE_URL
See what is on your PATHecho $PATH
Add one line to a config fileecho "node_modules" >> .gitignore
Report progress from a scriptecho "deploying..."
Create a file with one line in itecho "# project" > README.md

Things that trip people up

> overwrites. Typing > when you meant to add a line to .gitignore or .env throws away the rest of the file. Adding is always >>.

A misspelled variable is not an error.

$ echo $NOPE

$ echo "[$NOPE]"
[]

A name that does not exist expands to nothing at all. Wrap it in brackets and you can see whether it is empty.

The shell expands *, not echo.

$ echo *.txt
notes.txt result.txt

echo never sees *.txt. The shell replaces it with the matching file names first, and hands the result over. That order is exactly why echo *.txt is worth typing before rm *.txt.

Do not echo secrets. They stay on the screen and in your shell history. If you only need to know whether a value is set, printing [$TOKEN] to see that it is not empty is enough.

Practise it hands-on

webterm.app

learn.webterm.app

>_WEBTERM LEARN

WebTerm Learn: from one command to actually using it

Commands stick when they show up in a real sequence of work, not one at a time. There is a course that builds them up in order.

See the course

Related commands

cat / printf / export

echo is also in the “Make the shell your own” section of the Linux Commands Cheat Sheet.

Frequently asked questions

What is echo actually for?
It prints text. In practice the most common use by far is checking what is inside an environment variable, as in `echo $PATH`.
Should I use single or double quotes?
Double quotes when you want the value of a variable, single quotes when you want the `$` text itself. Inside double quotes `$USER` is replaced by its value; inside single quotes it is left alone.
What is the difference between `>` and `>>`?
`>` overwrites and `>>` appends. Using `>` when you meant to add one line to a config file wipes out everything that was there.
What does echo -n do?
It leaves off the final newline. Output normally ends with one, so you only add -n when you do not want it.
What happens if I misspell a variable name?
Nothing fails. The name expands to an empty string, so wrapping it as `echo "[$NAME]"` is the quickest way to see whether it is really empty.