The Wayback Machine - https://web.archive.org/web/20240118173833/https://www.geeksforgeeks.org/bash-scripting-bash-echo-command/
Open In App
Related Articles

Bash Scripting – Bash Echo Command

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report

In this article, we are going to see the echo command. The Echo command is a built-in command feature for Unix / Linux which is generally used to display the text or message on the screen.

Syntax :

$ echo [option]

For Example :

$ echo Geeks For Geeks

Output :

Geeks For Geeks

Output

There are generally three options:

  • -n: It does not print the trailing newline.
  • -E: It is the default option that disables the implementation of escape sequences.
  • -e: It is used to enable interpretation of backslash escapes

There are some escape sequences performing different operations such as:

Escape Sequences

Meaning

\b Backspace
\\ Backslash
\n New Line
\r Carriage Return
\t Horizontal Tab
\v Vertical Tab

Example 1 :

$ echo -e "Geeks \bFor \bGeeks"

Output:

GeeksForGeeks

Output

Example 2 :

$ echo -e "Geeks\nFor\nGeeks"

Output :

Geeks
For  
Geeks

Output

Example 3 :

$ echo -e "Geeks\tFor\tGeeks"

Output :

Geeks   For     Geeks

Output

Example 4 :

$ echo -e "Geeks\\For\\Geeks"  

Output : 

Geeks\For\Geeks

Output

Example 5 :

$ echo -e "Geeks\rFor Geeks"

Output : 

For Geeks

Output

Example 6 :

$ echo -e "Geeks\v For\v Geeks"

Output :

Geeks♂ For♂ Geeks

Output

Example 7 :

$ echo -n "Geeks For Geeks"

Output :

Geeks For Geeks

Output

You can find all the commands related to echo by writing the following command.

$ /bin/echo --help

Output : 

Output

There are some other ways to use echo command

Taking input from user: 

We create a text file named ” userInput.sh ” and write the following code inside the file. 

#!/bin/sh  

echo "Enter Your Name : "

read name     #It take input from user

echo "Hello, $name. Welcome to GeeksForGeeks"

Now run the ” userInput.sh ” with the help of the below code:

$ chmod +x ./userInput.sh
$ ./userInput.sh

Output :

Output

Learn to code easily with our course Coding for Everyone. This course is accessible and designed for everyone, even if you're new to coding. Start today and join millions on a journey to improve your skills!

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Commit to GfG's Three-90 Challenge! Purchase a course, complete 90% in 90 days, and save 90% cost click here to explore.
Last Updated : 22 Nov, 2021
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads
Complete Tutorials