FactorPad
Faster Learning Tutorials

Linux echo command summary with examples

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.
Paul Alan Davis, CFA, October 12, 2016
Updated: July 28, 2018
In this tutorial, 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 Next

~/ home  / tech  / linux essentials  / echo command


The Linux echo command

Beginner

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

Video Tutorial

Linux echo command summary with examples (4:16)

Videos can also be accessed from the YouTube Playlist.

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.

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?

Here's a link to quickly subscribe to our YouTube Channel.

  • For the Outline to all 100 tutorials, click Outline.
  • To go back to the which command, hit Back.
  • For the most basic text editor included with most distributions of Linux, called nano, click Next.

Outline Back Next

~/ home  / tech  / linux essentials  / echo command



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