The echo command takes the text or file as an argument and prints the output on the terminal screen.
It is mostly used in shell scripts when developers create a variable and use the variable to print the value on screen using the echo command.
Tutorial Details
| Description | Echo command |
| Difficulty Level | Low |
| Root or Sudo Privileges | No |
| OS Compatibility | Ubuntu, Manjaro, Fedora, etc. |
| Prerequisites | echo |
| Internet Required | No |
Syntax of the Echo Command
The echo command usually takes one argument as input if you are not using it with flags.
$ echo [OPTION] [STRING]Printing a Text Message
You can use the echo command to print a string without using single or double quotes.
$ echo linuxtldr.comOutput:

Even multiple strings can be printed without using single or double quotes.
$ echo follow linuxtldr.comOutput:

However, if you replace the argument with the β*β sign, it will output all the files and directories in your current working directory, acting similarly to the ls command.
$ echo *Output:

Printing the PATH Environment Variables
All the commands you execute from your terminal are searched at the location that is added to your environmentβs $PATH.
Execute the following command to view all the paths added to your environment variables.
$ echo $PATHOutput:

Printing a Message Without the Trailing New Line
When you execute the echo command to print the output on screen, it will appear in a newline because the echo command automatically instructs the output to be in a new line.
Although, you can easily omit the echoing trailing newline using the β-nβ flag.
$ echo -n Hello, folks!Output:

Redirecting the Echo Output to the New File
The output of the echo command can be saved in a new or existing file using the file redirection signs.
$ echo Hello, folks! >> file.txt
$ cat file.txt Output:

-eβ flag, which enables the interpretation of backslash escapes (special characters).Removing the Spaces Between the Text
The β\bβ backspace with the backslash interpreter β-eβ will remove the spaces between the text.
$ echo -e "We \bAre \bLinux \bTLDR"Output:

Removing the Trailing New Line
The β\cβ suppresses the trailing new line with the backslash interpreter β-eβ, which will add each line without emitting a new line.
$ echo -e "We Are Linux \cTLDR"Output:

Creating a Trailing New Line
The β\nβ trailing new line with the backslash interpreter β-eβ will create a new line each time β\nβ is specified.
$ echo -e "We \nAre \nLinux \nTLDR"Output:

Creating a Horizontal Tab Space
The β\tβ horizontal tab with the backslash interpreter β-eβ will create a horizontal tab space each time itβs specified.
$ echo -e "We \tAre \tLinux \tTLDR"Output:

Creating Vertical Tab Space
The β\vβ vertical tab with the backslash interpreter β-eβ will create a vertical tab space on each occasion it is specified.
$ echo -e "We \vAre \vLinux \vTLDR"Output:

Carriage Return in Output
The β\rβ carriage return with the backslash interpreter β-eβ will return the specified carriage in output.
$ echo -e "We Are \rLinux TLDR"Output:

Alert Return with Sound
The β\aβ alert return with the backslash interpreter β-eβ will have a sound alert.
$ echo -e "\aWe Are Linux TLDR"Output:

Echo Options
| Β Options | Β Description |
-n | Print the message without the trailing newline |
-e | enable interpretation of backslash escapes |
\b | Removing the spaces between the text |
\\ | backslash |
\c | omit the trailing newline |
\n | Creating a trailing newline |
\t | Creating horizontal tab space |
\v | Creating vertical tab space |
\r | Carriage return in output |
\a | Alert return with sound |
That was the end. Sayonara!




