Skip to content

Linux commands: echo

A quick guide to the `echo` command, used to print the argument passed to it

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

This example:

echo "hello"

will print hello to the terminal.

We can append the output to a file:

echo "hello" >> output.txt

We can interpolate environment variables:

echo "The path variable is $PATH"

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

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:

echo *

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

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:

echo ~

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

echo $(ls -al)

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

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

echo {1..5}

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

β†’ Download my free CLI Handbook!

THE VALLEY OF CODE

THE WEB DEVELOPER's MANUAL

You might be interested in those things I do:

  • Learn to code in THE VALLEY OF CODE, your your web development manual
  • Find a ton of Web Development projects to learn modern tech stacks in practice in THE VALLEY OF CODE PRO
  • I wrote 16 books for beginner software developers, DOWNLOAD THEM NOW
  • Every year I organize a hands-on cohort course coding BOOTCAMP to teach you how to build a complex, modern Web Application in practice (next edition February-March-April-May 2024)
  • Learn how to start a solopreneur business on the Internet with SOLO LAB (next edition in 2024)
  • Find me on X

Related posts that talk about cli: