Vol. I · No. 46The command line sectionSat, 10 Oct 2026
Linux · reading files

echo

print text

echo writes out whatever follows it. On its own that is trivial; with redirection it creates and appends to files, and with a dollar sign it shows what a variable holds.

> replaces a file’s contents; >> adds to the end. One character apart.

Prints
Its arguments
then a new line
Variables
$NAME
expanded inside double quotes
To a file
> and >>
overwrite and append
Built in
To the shell
no separate program needed

At the terminal

Read the session first, then the notes: each numbered line in the output is answered by the note with the same number.

user@netflow — bashbash
$ echo "Hello, $USER"
1Hello, user
2$ echo 'Hello, $USER'
Hello, $USER
3$ echo "nameserver 192.0.2.53" > resolv.test
4$ echo "nameserver 192.0.2.54" >> resolv.test
$ cat resolv.test
nameserver 192.0.2.53
nameserver 192.0.2.54
Illustrative session · names, sizes and dates are examples, and every address is from a documentation or private range
Reading the output

What the numbered lines are telling you

1
Double quotes expand variables

$USER was replaced by its value before echo ran. The shell does the substituting; echo only prints.

2
Single quotes do not

Everything inside single quotes is taken literally, dollar sign included.

3
> writes to a file

The output goes to the file instead of the screen. If the file existed, its old contents are gone.

4
>> appends

The second line is added after the first. This is the usual way to add one line to a configuration file.

Switches

A switch changes how the command behaves. These are the ones used day to day; man echo lists the rest. Single-letter switches can usually be joined, so -l -a may be written -la.

-n
Do not add a new line at the end.
-e
Interpret escapes such as \n for a new line and \t for a tab.
-E
Do not interpret escapes. This is the default in bash.

Variations worth knowing

The same tool, pointed at a narrower question. These four cover most of what it is reached for day to day.

echo $PATH

Shows the value of a variable.

echo $?

Shows the exit status of the last command: 0 means success.

echo -e "one\ttwo\nthree"

Interprets \t as a tab and \n as a new line.

echo "text" | sudo tee -a /etc/hosts

Appends to a root-owned file — sudo echo with >> does not work.

In cybersecurity

Whatever you echo is recorded in your shell history.

Secrets on the command line

echo "password" | some-command leaves the password in ~/.bash_history. Read it with "read -s" instead, or from a file.

One > can destroy a file

Typing > where >> was meant replaces the whole file with one line. Keep a copy before appending to anything that matters.

sudo does not apply to the redirect

In "sudo echo x > /etc/file" the shell, running as you, opens the file — and is refused. Pipe to "sudo tee" instead.

Filed under

Reading files

Read alongside