echo Command in Linux
Build an AI-First Career, Master the Complete Skillset
Choose from our industry-leading programs designed for career success
Modern Software and AI Engineering Program
Master full-stack development with AI integration
+1000 moreModern Data Science and ML with specialisation in AI
Advanced data science techniques with AI specialization
+1000 moreAdvanced AIML with Specialisation in Agentic AI
Deep dive into AIML with focus on Agentic systems
+1000 moreDevOps, Cloud & AI Platform Engineering
Build and manage AI-powered cloud infrastructure
+1000 moreAI Engineering Advanced Certification by IIT-Roorkee
Premier AI engineering certification from IIT-Roorkee
AI Forward Deployed Engineer Program
Full-stack engineering, production AI and client-facing consulting
+1000 moreOverview
In Linux, the echo command is used to display a line of text on the terminal. It is a simple and commonly used command. This article will explain the syntax, options, and some example usages of the echo command.
Linux echo Command Syntax
The syntax for the echo command is as follows:
Where:
- OPTIONS: The options are used to modify the output of the echo command. The -n option is used to avoid the trailing newline character. The -e option is used to enable interpretation of backslash escapes. The -E option is used to disable the interpretation of backslash escapes, which is the default behavior.
- STRING: The string specifies the text that needs to be displayed on the terminal. It can be a word, sentence, or a combination of both.
echo Command Options:
- -n: Do not output the trailing newline character.
- -e: Enable interpretation of backslash escapes.
- -E: Disable interpretation of backslash escapes (default).
Example Usages
-
Display a single word on the terminal::
Output:
Explanation: The echo command is used to display the word 'Hello' on the terminal. The output also includes a newline character.
-
Display a sentence on the terminal::
Output:
Explanation: The echo command is used to display the sentence 'This is a sentence.' on the terminal. The output also includes a newline character.
How Scaler Transformed Careers in Different Fields
Scaler learners achieved 2.5x salary growth with average post-Scaler CTC reaching ₹23L.
Tips
-
The echo command is commonly used to display messages or display the value of variables.
-
To display a message without a newline character, use the -n option.
-
To display a message with special characters, use the -e option.
Advanced Use Cases of echo Command in Linux
-
Display multiple words on the terminal::
Output:
Explanation: The echo command is used to display the words 'Hello World' on the terminal. The output also includes a newline character.
-
Display a message without a newline character::
Output:
Explanation: The echo command with the -n option is used to display the message 'This is a message' on the terminal. The output does not include a newline character.
-
Display a message with special characters::
Output:
Explanation: The echo command with the -e option is used to display the message 'This is a newline' on the terminal. The '' sequence is interpreted as a newline character, so the output includes a newline character.
Turn Learning into Career Growth
Conclusion
-
The echo command is a simple and commonly used command in Linux.
-
It is used to display messages or the value of variables on the terminal.
-
The echo command can be modified using options like -n and -e.
-
The -n option is used to avoid the trailing newline character, and the -e option is used to enable interpretation of backslash escapes.
-
Use the echo command with caution when working with user input, as it can execute shell commands if the input is not sanitized properly.