Echo Command in Linux

The Echo command in Linux is just like the “cout” command in C++. The Echo command is used to display anything passed to this command as an argument on the terminal as an output. Echo is very frequently used with code that is written in the form of shell scripts. You can make use of this command to display anything on your screen.

Apart from this general description, the Echo command is also used in conjunction with some other parameters to perform useful functions. This article will cover the basic usage of the Echo command as well as its combinational usage with some other parameters to display the desired output.

How to Use Echo Command in Linux?

To use the Echo command in Linux, perform the following steps:

First, launch the terminal in Ubuntu 20.04 by pressing Ctrl+ T or by clicking on the Activities icon on your desktop.

Type ‘terminal’ in the search bar that appears.

Double click on the search results to launch the terminal.

You can also right-click on your desktop and then select the Open Terminal option from the menu that pops up.

The newly launched terminal window is shown in the image below:

After launching the terminal, type the following command on your terminal and then press the Enter key:

echo “My Text to Display”

Here, replace “My Text to Display” with the text that you want to be displayed. In this example, I wanted to display “My Name is Karim” so I have written this statement in the inverted commas.

The Echo command will display this text on the terminal, as shown in the following image:

This is a basic way to use the Echo command. Next, we will teach you how to combine this command with some other parameters to display a different-looking output.

Removing Text Spacing

To remove the text spacing, type the following command in your terminal and then press the Enter key:

echo –e “My \bText \bTo \bDisplay”

Replace the text inside the inverted commas with your desired text. The output of this command is shown in the image below:

Omitting the Desired Text after the Additional Parameter

To omit the portion of text after the additional parameter, type the following command in your terminal and then press the Enter key:

echo –e “My Text \cTo Display”

Replace the text inside the inverted commas with your desired text. The output of this command is shown in the image below:

Displaying the Text in Multiple Lines

If you want your text to span multiple lines, type the following command in your terminal and then press the Enter key:

echo –e “My \nText \nTo \nDisplay”

Replace the text inside the inverted commas with your desired text. The output of this command is shown in the image below:

Displaying the Text with Horizontal Tab Spaces

To display your text with horizontal tab spaces, type the following command in your terminal and then press the Enter key:

echo –e “My \tText \tTo \tDisplay”

Replace the text inside the inverted commas with your desired text. The output of this command is shown in the image below:

Omitting the Desired Text before the Additional Parameter

To omit the portion of text before the additional parameter, type the following command in your terminal and then press the Enter key:

echo –e “My Text \rTo Display”

Replace the text inside the inverted commas with your desired text. The output of this command is shown in the image below:

Displaying the Text with Vertical Tab Spaces

To display your text with vertical tab spaces, type the following command in your terminal and then press the Enter key:

echo –e “My \vText \vTo \vDisplay”

Replace the text inside the inverted commas with your desired text. The output of this command is shown in the image below:

Producing a Sound Alert with the Text

If you want your text to be displayed with a beep, then type the following command in your terminal and then press the Enter key:

echo –e “\aMy Text to Display”

Replace the text inside the inverted commas with your desired text. This command will display the text as it is as it displays it with the simple Echo command however, it will also produce a sound this time. The output of this command is shown in the image below:

Printing all the Files/ Folders

To print all the files and folders, type the following command in your terminal and then press the Enter key:

echo *

The output of this program is shown in the following image:

Omitting the Newline Character

If you want your text to be displayed within the same line, type the following command in your terminal and then press the Enter key:

echo –n “My Text to Display”

Replace the text inside the inverted commas with your desired text. The output of this command is shown in the image below:

Conclusion

In this way, you can either use the simple Echo command or combine it with some other parameters to display the desired output. You can also play around with this command by experimenting with it and combining more than one parameter and then observing the output. This article simply covered the basic knowledge of the Echo command and its various parameters.



from Linux Hint https://ift.tt/3fI2EFW

Post a Comment

0 Comments