> For the complete documentation index, see [llms.txt](https://kgk.gitbook.io/resources/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://kgk.gitbook.io/resources/resources/linux/commands/echo-command.md).

# Echo command

### The Linux `echo` command <a href="#the-linux-echo-command" id="the-linux-echo-command"></a>

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"
```

<img src="https://www.freecodecamp.org/news/content/images/2020/10/Screen-Shot-2020-09-03-at-15.44.33.png" alt="Screen-Shot-2020-09-03-at-15.44.33" height="264" width="793">

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

![Screen-Shot-2020-09-03-at-15.51.18](https://www.freecodecamp.org/news/content/images/2020/10/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 ~
```

<img src="https://www.freecodecamp.org/news/content/images/2020/10/Screen-Shot-2020-09-03-at-15.46.36.png" alt="Screen-Shot-2020-09-03-at-15.46.36" height="264" width="793">

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

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

<img src="https://www.freecodecamp.org/news/content/images/2020/10/Screen-Shot-2020-09-03-at-15.48.55.png" alt="Screen-Shot-2020-09-03-at-15.48.55" height="289" width="793">

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

<img src="https://www.freecodecamp.org/news/content/images/2020/10/Screen-Shot-2020-09-03-at-15.49.53.png" alt="Screen-Shot-2020-09-03-at-15.49.53" height="314" width="793">

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

```bash
echo {1..5}

```

<figure><img src="https://www.freecodecamp.org/news/content/images/2020/10/Screen-Shot-2020-09-03-at-15.47.19.png" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://kgk.gitbook.io/resources/resources/linux/commands/echo-command.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
