echo Command in Linux

Learn via video courses
Topics Covered

Overview

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.

Transform Your Career

Choose from our industry-leading programs designed for career success

NSDC Certified

Modern Software and AI Engineering Program

Master full-stack development with AI integration

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Modern Data Science and ML with specialisation in AI

Advanced data science techniques with AI specialization

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Advanced AIML with Specialisation in Agentic AI

Deep dive into AIML with focus on Agentic systems

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

DevOps, Cloud & AI Platform Engineering

Build and manage AI-powered cloud infrastructure

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

AI Engineering Advanced Certification by IIT-Roorkee

Premier AI engineering certification from IIT-Roorkee

3 MonthsDuration
AI-LedCurriculum
Career SupportSupport
Program highlights
Go to Program

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).

Transform Your Career

Choose from our industry-leading programs designed for career success

NSDC Certified

Modern Software and AI Engineering Program

Master full-stack development with AI integration

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Modern Data Science and ML with specialisation in AI

Advanced data science techniques with AI specialization

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Advanced AIML with Specialisation in Agentic AI

Deep dive into AIML with focus on Agentic systems

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

DevOps, Cloud & AI Platform Engineering

Build and manage AI-powered cloud infrastructure

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

AI Engineering Advanced Certification by IIT-Roorkee

Premier AI engineering certification from IIT-Roorkee

3 MonthsDuration
AI-LedCurriculum
Career SupportSupport
Program highlights
Go to Program

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.

Scaler Placement Report and Statistics

₹23L
AVG CTC
SCALER PLACEMENT PROOF

Scaler learners achieved 2.5x salary growth with average post-Scaler CTC reaching ₹23L.

11,000+placements
650+companies
Verified data

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.

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.