Skip to main content

Module 1: File & Directory Management

Lesson 13: echo Command

In this lesson, you'll learn how to use the echo command to display text and strings on standard output in Linux.

The echo command is one of the most commonly and widely used built-in commands for Linux bash and C shells, typically used in a scripting language and batch files to display a line of text/string on standard output or a file.

echo Command Syntax

echo [option(s)] [string(s)]

echo Command Options

Option Description
-n Do not print the trailing newline
-e Enable interpretation of backslash escapes
\b Backspace
\\ Backslash
\n New line
\r Carriage return
\t Horizontal tab
\v Vertical tab

1. Display a Line of Text on Standard Output

Input a line of text and display it on standard output.

$ echo Tecmint is a community of Linux Nerds
Tecmint is a community of Linux Nerds

2. Declare a Variable and Echo Its Value

Declare a variable and echo its value. For example, declare a variable x and assign its value 10.

$ x=10

Echo its value:

$ echo The value of variable x = $x
The value of variable x = 10

Note: The -e option in Linux acts as an interpretation of escaped characters that are backslashed.

3. Use Backspace Option with echo

Using option \b - backspace with backslash interpreter -e which removes all the spaces in between.

$ echo -e "Tecmint \bis \ba \bcommunity \bof \bLinux \bNerds"
TecmintisacommunityofLinuxNerds

4. Use New Line Option with echo

Pro TecMint Β· Root Plan
This Article is for Root Members
Join Root to read the full article and unlock everything

Full Access to Every Article, Course & Certification Track

Join thousands of Linux professionals who use Pro TecMint to advance their careers.

Ad-free access to all premium articles
All courses: Learn Linux, Bash, Golang, Ubuntu and more
RHCSA, RHCE, LFCS & LFCA certification prep
New courses added every month
Private Telegram community & priority support
Root Plan
$8/mo
or $59/year billed annually
Save $37 with annual plan
Start Reading This Article in the Next 60 Seconds
Join Root Plan β†’