A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/linux-unix/bash-scripting-bash-echo-command/ below:

Bash Scripting - Bash Echo Command

Bash Scripting - Bash Echo Command

Last Updated : 18 Apr, 2024

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][text]

For Example :

$ echo Geeks For Geeks

Output :

Geeks For Geeks
Output There are generally three options: Some escape sequences perform different operations such as: Escape Sequences Meaning \b Backspace \\ Backslash \n New Line \r Carriage Return \t Horizontal Tab \v Vertical Tab Example 1: Backspace
$ echo -e "Geeks \bFor \bGeeks"

Output:

GeeksForGeeks
Output Example 2: New Line
$ echo -e "Geeks\nFor\nGeeks"

Output :

Geeks
For  
Geeks
Output Example 3: Horizontal Tab
$ echo -e "Geeks\tFor\tGeeks"

Output :

Geeks   For     Geeks
Output Example 4: Backslash
$ echo -e "Geeks\\For\\Geeks"  

Output : 

Geeks\For\Geeks
Output Example 5: Carriage Return
$ echo -e "Geeks\rFor Geeks"

Output : 

For Geeks
Output Example 6: Vertical Tab
$ echo -e "Geeks\v For\v Geeks"

Output :

Geeks♂ For♂ Geeks
Output Example 7: -n Option
$ 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 Conclusion

In conclusion, the echo command is a versatile and powerful built-in command in Unix/Linux systems that allows users to display text or messages on the screen. The article provided a detailed overview of the echo command's syntax, options, and various examples demonstrating its usage, including the ability to suppress newline characters, enable/disable escape sequence interpretation, and display special characters like backspaces, tabs, and carriage returns. The article also covered how to take input from users using the echo and read commands together. Overall, the echo command is an essential tool in a Unix/Linux user's toolkit, enabling effective text manipulation and output display within the command-line environment.



RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4