The echo command is a useful choice for writing text in a terminal window. Its main task is to display text or string but not necessarily static text.
This command is available and is commonly used in shell scripts and batch files. Also it is often used to output the results of other commands.
Here at Ibmi Media, as part of our Server Management Services, we regularly help our Customers to perform related Linux system queries.
In this context, we shall look into how to use the echo command in Linux.
It's syntax is given below:
$ echo [option] [string]
For example, use the following command to print Hello, World! as the output:
$ echo Hello, World!
The output will give:
Hello, World!
The available Echo command Options can be displayed by using the --help argument as shown below:
/bin/echo --help
The echo command uses the following options:
1. \b remove all spaces
For Example, the below command:
$ echo -e "Hello \bWorld"
The output will be:
HelloWorld
You must use -e for the command to understand the meaning of "\"
2. \c remove the line after the option
For Example:
$ echo -e "Hello \cWorld"
The output will be:
Hello
3. \n split newline
For Example:
$ echo -e "Hello \nWorld"
The output will be:
Hello
World
4. \t separated by horizontal tab
For Example:
$ echo -e "Hello \tWorld"
The output will be:
Hello World
5. \r remove the line before the option
For Example:
$ echo -e "Hello \rWorld"
The output will be:
World
6. \v separated by vertical tab
For Example:
$ echo -e "Hello \vWorld"
The output will be:
Hello
World
7. echo* list all files/folders
For Example:
$ echo *
This article covers how to use echo command in Linux. In fact, Echo Command is used to display the text that has been passed as argument for the command. Also, it is used as a input for the next command or to send output to a file.
Syntax for using the Echo command in Linux is:
# echo option string