Echo Team in Linux

Anonim

Echo Team in Linux

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.

  1. 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.
  2. Using the ECHO command in Linux without applying additional options

  3. As you can see, in the new line, the newly entered words in exactly the same format appeared.
  4. The result is the use of the ECHO command in Linux without additional options.

  5. 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".
  6. Using ECHO in Linux with the deletion option of the previous symbol

  7. We put the specified option in all words, so the result turned out to be appropriate.
  8. The result of using ECHO in Linux with the deletion option of the previous symbol

  9. 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.
  10. Using ECHO in Linux with a transfer option to a new string

  11. We indicated \ n in a nutshell after the first, therefore, each of them will be displayed in a new row.
  12. The result is the use of the ECHO command in Linux with the transfer option to the new string

  13. 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.
  14. Using ECHO in Linux with tab option

  15. As can be seen, to the first word, the tabulation was applied twice. Consider this when the lines are displayed.
  16. The result of using the ECHO command in Linux with tab option

  17. Additionally, nothing interferes with specifying several options sequentially, observing the input rules.
  18. Combining options when using the echo command in Linux

  19. For example, on the screenshot below you see the result of output with the transfer and tab at the same time.
  20. The result of combining options when using the ECHO command in Linux

  21. As the last example, take / v. This argument creates a vertical tab.
  22. Using the vertical tab option for ECHO command in Linux

  23. As a result, each word is obtained from a new line and in the form of steps.
  24. The result of using the vertical tab for the echo command in Linux

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.

  1. 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.
  2. Creating a variable for further output via ECHO in Linux

  3. Use Echo $ i to display the value of the designated variable in the following line.
  4. Enter ECHO command in Linux using the created variable

  5. As you can see, everything is displayed correctly.
  6. The result of the echo command in Linux using the variable

  7. Create another variable through Export L = Linux.
  8. Creating a second variable for combined input in ECHO in Linux

  9. We introduce the trial command Echo $ I Site $ L.
  10. Combined input with two echo variables in Linux

  11. Now you know that Echo copes with the output of two or more variables in the format of one line.
  12. The result of combined input with two echo variables in Linux

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".

Using the echo command in Linux to change the color of the rows

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.

The result of applying Echo options in Linux to change the color of rows

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.

  1. Enter Echo * in Terminal to show the contents of the current folder.
  2. Using the ECHO command in Linux to display the contents of the current folder

  3. 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.
  4. ECHO command action in Linux after displaying the contents of the current folder

  5. Specify Echo * .txt if you want to display only the elements of the designated format. Replace .txt to another required option.
  6. Using the echo command in Linux to output a specific file format

  7. 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.
  8. Using the echo command in Linux to change configuration files

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

Read more