/ factorpad.com / tech / linux-essentials / echo-command.html
An ad-free and cookie-free website.
Beginner
Learn to display text and variables at the Linux command line.
Videos can also be accessed from the Linux Essentials Playlist on YouTube.
Linux echo command summary with examples (4:16)
Our nineteenth word, or command to memorize is echo
from the category
Text.
echo
allows you to display text and
variables.
-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.
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
.
Uh oh, this is a (shell) builtin quirk, so point to the program using
/bin/echo
if you have this issue on
your system.
And then let's type echo Paul likes echo
.
Good. Next, let's type in double-quotes
echo "Paul likes echo"
.
Or echo 'Paul likes echo'
like this.
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.
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.
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.
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.
For an overview of the 100 videos, the 8 quizzes, a cheat sheet, the categories and a Q&A section, visit:
Make sure to connect while you're here so you don't lose this valuable ad-free resource.
which
command,
hit Back.nano
, click Next./ factorpad.com / tech / linux-essentials / echo-command.html
A newly-updated free resource. Connect and refer a friend today.