Table of Contents
Introduction
The echo command in Linux is a versatile tool used for printing text or variables to the terminal or redirecting them to a file. It is a simple yet powerful command that finds wide usage in shell scripting and day-to-day Linux operations.
In this tutorial, we will delve into the echo command, exploring its functionality and providing practical examples to illustrate its usage. echo command means Echo the STRING(s) to standard output.
Syntax
echo [SHORT-OPTION]… [STRING]…
echo LONG-OPTION
On the man page, the describes it
- echo – display a line of text.
- man echo– More details information about echo command.
echo command in Linux with Examples
$ echo "Welcome to DevopsRoles.com !"
Example 1: Printing a Message
echo "Hello, world!"
Example 2: Outputting Variable Values
name="HuuPV"
age=33
echo "Name: $name"
echo "Age: $age"
Options and Flags
Example 3: Using the -n Flag
echo -n "This is "
echo "a single line."
Example 4: Using the -e Flag
echo -e "Line 1\nLine 2\tTabbed Line 3"
Example 5: Redirecting Output to a File
echo "This is some content." > output.txt
This command creates a file named output.txt and writes the text “This is some content.” into it.
Conclusion
echo command in Linux is a simple command in Linux. It is the most popular in-use terminal Linux displays a line of text. Thank you for reading the DevopsRoles page!