As you know, most of the actions in the Linux operating system are carried out through the console. Users will use special commands responsible for performing certain processes, and in advance the specified options allow their own hands to control the additional possibilities of the most utilities. One of these commands is Echo, and today we want to tell more in detail about this utility, bringing several examples of its use.
We use the echo command in Linux
The Echo team under consideration today has a primitive look and a narrow-profile destination - display text on the screen. However, this does not interfere with it often used in various scripts and for other purposes. Next, we propose briefly familiarize yourself with the syntax of this utility and disassemble the most popular and simple examples of its input in the standard console.Echo syntax
Almost every team, in addition to the main function, can also perform other actions taking into account the specified arguments. Echo did not exception in this regard, however, due to the simplicity of the Advanced Options itself, there is not so much. Let's consider it more about each of them, but first pay attention to the standard view of the line: echo + options + string.
- -n - it will not display the transfer of the line;
- -e - responsible for the inclusion of escape sequences;
- -E - disables the interpretation of Escape sequences.
We also note that Escape sequences are universal options presented in the form of symbols. Each of them has a definite value, and if you enable interpretation when using the ECHO command, you can use such arguments:
- / C - responsible for deleting the transfer of the string;
- / T - displays a horizontal tab;
- / V - creates a vertical tab;
- / b - removes the previous symbol in the string;
- / n - includes the transfer of the string to the new one;
- / R - returns the carriage to the beginning of the line.
Once again, we clarify the above options are available to enter only in those situations where you initially prescribed the argument -E in the team. If necessary, each of this symbol can be improved after any of the words input string that we will show in the following instructions.
Conclusion of simple string
As mentioned earlier, the main purpose of the ECHO command is the output to the string screen. It is about this that we want to talk further, examined a few simple actions that will help to understand exactly how all the main options utilities work.
- Run the console convenient for you, for example, through the application menu or by pressing the Ctrl + Alt + T hot key. Here enter echo + any word or phrase to check the standard action command. It is activated by pressing the Enter key.
- As you can see, in the new line, the newly entered words in exactly the same format appeared.
- If you add an option \ B before each word, the previous character will be erased, which means that the result will be displayed without spaces, provided that we have the original view of Echo -e "Lumpics \ Bsite \ blinux".
- We put the specified option in all words, so the result turned out to be appropriate.
- Now let's pay attention to the \ n parameter. As you already know, it activates the transfer of the string, if it was not indicated initially.
- We indicated \ n in a nutshell after the first, therefore, each of them will be displayed in a new row.
- We turn to the tab that is used to align text. You will sufficiently register in the necessary places \ t to achieve the desired result.
- As can be seen, to the first word, the tabulation was applied twice. Consider this when the lines are displayed.
- Additionally, nothing interferes with specifying several options sequentially, observing the input rules.
- For example, on the screenshot below you see the result of output with the transfer and tab at the same time.
- As the last example, take / v. This argument creates a vertical tab.
- As a result, each word is obtained from a new line and in the form of steps.
Now you know that the ECHO command is capable of displaying specified lines in any form that can be implemented by specifying the appropriate options. Let's go to other parameters so that you understand which of them are to combine in the right format.
The output of the variable values
In almost every script, certain variables are used in which the value is in advance. If we are talking about an ECHO utility, then it is able to output the very meaning. We will consider this example in one terminal session without the prior creation of the script itself. This denotes that when restarting the console, the values will be erased.
- To begin with, creating a trial variable by entering Export i = Lumpics, where i is the name of the variable, and Lumpics is its value.
- Use Echo $ i to display the value of the designated variable in the following line.
- As you can see, everything is displayed correctly.
- Create another variable through Export L = Linux.
- We introduce the trial command Echo $ I Site $ L.
- Now you know that Echo copes with the output of two or more variables in the format of one line.
In most cases, this output of variables is used only when writing scripts, however, such a function can be useful if it is planned to produce a number of identical dependent on one value, actions within one terminal session.
Assigning colors string
If you are actively using the console, you know that each word can take any available color here, and not just white or black (depending on the topic "Terminal"). Echo also allows you to paint lines, and responsible for this such arguments:
- \ 033 [30m - black;
- \ 033 [31m - red;
- \ 033 [32m - Green;
- \ 033 [33m - yellow;
- \ 033 [34m - blue;
- \ 033 [35m - purple;
- \ 033 [36m - blue;
- \ 033 [37m - gray.
There are a number of other arguments that allow you to change the color of the inscription background. Looks like a list similar, but there are differences in numbers:
- \ 033 [40m - black;
- \ 033 [41m - red;
- \ 033 [42m - Green;
- \ 033 [43m - yellow;
- \ 033 [44m - blue;
- \ 033 [45m - purple;
- \ 033 [46m - blue;
- \ 033 [47m - gray;
- \ 033 [0m - resets all values to the default state.
As you already understood, these arguments will have to be applied to each row if there is a need. Looks like a similar structure as follows: echo -e "\ 033 [33mlumpics \ 033 [46msite \ 033 [41mlinux".
The example above was colored Lumpics background in an orange color, and the backgrounds of different colors were additionally activated to "Site" and "Linux". You see this in the screenshot below the entered command.
Special Bash characters
The ECHO command function only in the Bash environment, respectively, it must maintain the standard options for this environment. In most cases, they are responsible for sorting files and output of the objects of the current location.
- Enter Echo * in Terminal to show the contents of the current folder.
- The next line will appear a list of absolutely all incoming directories and elements. It will be a standard string without registration. However, now you already know that it can be modified on the basis of examples above.
- Specify Echo * .txt if you want to display only the elements of the designated format. Replace .txt to another required option.
- In the end, we note that ECHO also performs to edit configuration files, which is carried out as follows: ECHO 1> / PROC / SYS / NET / IPv4 / IP_Forward. 1 - string for application, A / PROC / SYS / NET / IPv4 / IP_Forward - path to the desired object.
As part of today's material, we dealt with ECHO in the Linux operating system. If you are interested in the topic of interaction with popular teams, additionally, we recommend to learn an article on this topic on our website, while moving below the links below.
See also:
Frequently used commands in "Terminal" Linux
LN / FIND / LS / GREP / PWD command in Linux