# Linux commands: echo

> Learn how the Linux echo command prints its argument to the terminal, interpolates variables like $PATH, expands globs and ranges, and appends to a file.

Author: Flavio Copes | Published: 2020-09-07 | Canonical: https://flaviocopes.com/linux-command-echo/

The `echo` command does one simple job: it prints to the output the argument passed to it.

This example:

```bash
echo "hello"
```

will print `hello` to the terminal.

We can append the output to a file:

```bash
echo "hello" >> output.txt
```

We can interpolate environment variables:

```bash
echo "The path variable is $PATH"
```

![Terminal showing echo command interpolating PATH variable displaying system directory paths](https://flaviocopes.com/images/linux-command-echo/Screen_Shot_2020-09-03_at_15.44.33.png)

Beware that special characters need to be escaped with a backslash `\`. `$` for example:

![Terminal showing echo command with and without escaped dollar sign demonstrating character escaping](https://flaviocopes.com/images/linux-command-echo/Screen_Shot_2020-09-03_at_15.51.18.png)

This is just the start. We can do some nice things when it comes to interacting with the shell features.

We can echo the files in the current folder:

```bash
echo *
```

We can echo the files in the current folder that start with the letter `o`:

```bash
echo o*
```

Any valid Bash (or any shell you are using) command and feature can be used here.

You can print your home folder path:

```bash
echo ~
```

![Terminal showing echo tilde command outputting the home directory path /Users/flavio](https://flaviocopes.com/images/linux-command-echo/Screen_Shot_2020-09-03_at_15.46.36.png)

You can also execute commands, and print the result to the standard output (or to file, as you saw):

```bash
echo $(ls -al)
```

![Terminal showing echo command executing ls -al subcommand with output displayed as single line](https://flaviocopes.com/images/linux-command-echo/Screen_Shot_2020-09-03_at_15.48.55.png)

Note that whitespace is not preserved by default. You need to wrap the command in double quotes to do so:

![Terminal showing echo command with quoted subcommand preserving whitespace formatting in directory listing](https://flaviocopes.com/images/linux-command-echo/Screen_Shot_2020-09-03_at_15.49.53.png)

You can generate a list of strings, for example ranges:

```bash
echo {1..5}
```

![Terminal showing echo command with brace expansion generating sequence 1 2 3 4 5 from {1..5}](https://flaviocopes.com/images/linux-command-echo/Screen_Shot_2020-09-03_at_15.47.19.png)

> The `echo` command works on Linux, macOS, WSL, and anywhere you have a UNIX environment
