Robert Elder Software Inc.
  • Home
  • Store
  • Blog
  • Contact
  • Home
  • Store
  • Blog
  • Contact
  • #linux
  • |
  • #commandline
  • |
  • #softwareengineering
  • |
  • #embeddedsystems
  • |
  • #compilers
  • ...
  • View All >>

Intro To 'echo' Command In Linux

2023-05-02 - By Robert Elder

     I use the 'echo' command to print pieces of text on the terminal:

echo "Hello World!"

     You can use the 'echo' command to print literal pieces of text like this:

echo "Text inside 'double' quotes."
echo 'Text inside "single" quotes.'
echo Text without quotes.

     The above three echo statements will output the following:

Text inside 'double' quotes.
Text inside "single" quotes.
Text without quotes.

Evaluating Variables With 'echo'

     You can also include variables and evaluate them like this:

echo "The current working directory is: $PWD"

     The above echo statement will output the following:

The current working directory is: /home/robert/important

Evaluating Commands With 'echo'

     You can even include the output from other commands.  If you run the date command by itself:

date

     the output will be something like this:

Wed 03 May 2023 11:24:47 AM EDT

     If we run the 'date' command in an echo statement like this:

echo "The current date is: $(date)"

     the output will look like this:

The current date is: Wed 03 May 2023 11:24:47 AM EDT

Evaluating Newlines With 'echo'

     By default, the 'echo' command won't evaluate escaped characters like newlines:

echo "pear\nbanana\napple"

     As you can see, the output still contains the literal '\n' characters:

pear\nbanana\napple

     You need to include the '-e' flag to evaluate them:

echo -e "pear\nbanana\napple"

     the output will then be the following:

pear
banana
apple

Piping The Output From 'echo'

     I can pipe the output of the 'echo' command into the sort command to sort the list of lines:

echo -e "pear\nbanana\napple" | sort
apple
banana
pear

     I can also pipe the output of the 'echo' command into the xxd command to see a hexadecimal representation of the output:

echo -e "pear\nbanana\napple" | xxd
00000000: 7065 6172 0a62 616e 616e 610a 6170 706c  pear.banana.appl
00000010: 650a                                     e.

     And that's why the 'echo' command is my favorite Linux command.

Intro To 'stty' Command In Linux
Intro To 'stty' Command In Linux
Published 2023-10-04
Terminal Block Mining Simulation Game
$1.00 CAD
Terminal Block Mining Simulation Game
Intro To 'nproc' Command In Linux
Intro To 'nproc' Command In Linux
Published 2023-07-15
Intro To 'comm' Command In Linux
Intro To 'comm' Command In Linux
Published 2023-09-06
How To Force The 'true' Command To Return 'false'
How To Force The 'true' Command To Return 'false'
Published 2023-07-09
A Surprisingly Common Mistake Involving Wildcards & The Find Command
A Surprisingly Common Mistake Involving Wildcards & The Find Command
Published 2020-01-21
A Guide to Recording 660FPS Video On A $6 Raspberry Pi Camera
A Guide to Recording 660FPS Video On A $6 Raspberry Pi Camera
Published 2019-08-01
Intro To 'chroot' Command In Linux
Intro To 'chroot' Command In Linux
Published 2023-06-23
Join My Mailing List
Privacy Policy
Why Bother Subscribing?
  • Free Software/Engineering Content. I publish all of my educational content publicly for free so everybody can make use of it.  Why bother signing up for a paid 'course', when you can just sign up for this email list?
  • Read about cool new products that I'm building. How do I make money? Glad you asked!  You'll get some emails with examples of things that I sell.  You might even get some business ideas of your own :)
  • People actually like this email list. I know that sounds crazy, because who actually subscribes to email lists these days, right?  Well, some do, and if you end up not liking it, I give you permission to unsubscribe and mark it as spam.
© 2025 Robert Elder Software Inc.
SocialSocialSocialSocialSocialSocialSocial
Privacy Policy      Store Policies      Terms of Use