FactorPad
Build a Better Process

Linux echo Command Summary with Examples

Linux echo allows you to display text and variables.
  1. Purpose - Learn what echo is for and how to find help.
  2. Options - Review a few common options and arguments.
  3. Examples - Walk through code examples with echo.
  4. A tip - Finish off with one more insight.
face pic by Paul Alan Davis, CFA
Updated: February 23, 2021
In this tutorial on Linux echo, 19 of 100, below find a 3-4 minute introductory video, a text-based tutorial and all of the code examples from the video.

Outline Back Tip Next

/ factorpad.com / tech / linux-essentials / echo-command.html


An ad-free and cookie-free website.


Examples of the Linux echo Command

Beginner

Learn to display text and variables at the Linux command line.

Video Tutorial

Videos can also be accessed from the Linux Essentials Playlist on YouTube.

Linux echo command summary with examples (4:16)

Video Script

The Command and Why You Need It

Our nineteenth word, or command to memorize is echo from the category Text.

echo allows you to display text and variables.

Common Linux echo Options
-options description
--help Print help screen
-E Disable backslash escape sequences (default)
-e Enable backslash escape sequences

Recall from the last video (tutorial) we touched on the PATH variable, well here we'll use echo to display that variable.

Before we start, it helps to think about commands as mini programs and most follow this structure: command -option(s) argument(s).

The echo command has 5 options and the argument is what you'd like to display.

Like most commands, find help using the double-dash --help option.

The -E option, the default, disables baskslash escape keys and -e turns this feature on. I'll demonstrate shortly.

So why is echo an important command? Well, we saw how the cat command in video #10 prints files. echo, alternatively, prints text or variables you input. And now you know how to do that.

Demonstration

Okay, the best way to embed this in your memory is by typing in your own terminal window.

Find this on your Mac using a program called Terminal. On Linux use Terminal or Konsole, and currently Microsoft is adding this functionality to Windows.

Here we go, type echo --help.

$ echo --help --help

Uh oh, this is a (shell) builtin quirk, so point to the program using /bin/echo if you have this issue on your system.

$ /bin/echo --help Usage: /bin/echo [SHORT-OPTION]... [STRING]... or: /bin/echo LONG-OPTION Echo the STRING(s) to standard output. -n do not output the trailing newline -e enable interpretation of backslash escapes -E disable interpretation of backslash escapes (default) --help display this help and exit --version output version information and exit If -e is in effect, the following sequences are recognized: \\ backslash \a alert (BEL) \b backspace \c produce no further output \e escape \f form feed \n new line \r carriage return \t horizontal tab \v vertical tab \0NNN byte with octal value NNN (1 to 3 digits) \xHH byte with hexadecimal value HH (1 to 2 digits) NOTE: your shell may have its own version of echo, which usually supersedes the version described here. Please refer to your shell's documentation for details about the options it supports. (last 3 lines trimmed)

And then let's type echo Paul likes echo.

$ echo Paul likes echo Paul likes echo

Good. Next, let's type in double-quotes echo "Paul likes echo".

$ echo "Paul likes echo" Paul likes echo

Or echo 'Paul likes echo' like this.

$ echo 'Paul likes echo' Paul likes echo

Interesting. Now, let's use the -e option. The \n keys translate to newline. There are a dozen escape sequences in help (above) area to check out.

$ echo -e "Paul \nlikes \necho" Paul likes echo

Then, a variable. Let's assign to the variable x, the word echo. Now, watch this, with a dollar sign, $, there we have that variable.

$ x=echo $ echo Paul likes $x Paul likes echo

And then let's see why Paul likes echo and quickly view the $PATH environment variable, showing a colon-separated list of directories Linux searches for commands. And here, you would type on your end echo $PATH. And because my $PATH is complex, so I've used the cat command here to show an example.

$ cat video19.txt /home/paul/bin:usr/local/bin:/usr/bin:/bin

A Final Tip

Okay now you know how to use echo. And you know the syntax for commands, options and arguments.

One last tip about the echo command. It's important to learn those escape sequences, so check those out.

Okay, thanks for visiting today. I hope this was a fun introduction to the echo command.


Learn More About The Series

For an overview of the 100 videos, the 8 quizzes, a cheat sheet, the categories and a Q&A section, visit:


What's Next?

Make sure to connect while you're here so you don't lose this valuable ad-free resource.

Outline Back Tip Next

/ factorpad.com / tech / linux-essentials / echo-command.html


linux echo command
echo command
echo linux
display text in linux
print variables in linux
echo command how to
echo command syntax
echo command summary
echo command examples
echo command options
echo command tutorial
linux echo video
echo PATH
echo man page
echo unix
bash echo
shell echo
echo options
echo variable

A newly-updated free resource. Connect and refer a friend today.