Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use the Linux echo command

Shulou Source: shulou.com Published: 2022-06-01 20:52:42 10月03日 Update

This article introduces the relevant knowledge of "how to use the Linux echo command". Many people will encounter such a dilemma in the operation of actual cases, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Syntax echo string you can use echo for more complex output format control.

Example 1. Enter a line of text and display it on standard output. $echo Tecmint is a community of Linux Nerds outputs the following text:

Tecmint is a community of Linux Nerds2. Output a declared variable value, for example, declare the variable x and assign it a value of 10.

$xroom10 will output its value:

$echo The value of variable x = $x The value of variable x = 103. Using the'\ b 'option'-e' followed by'\ b 'removes all spaces between characters.

Note: the option'- e' in Linux acts as a translator for the backslash of escaped characters.

$echo-e "Tecmint\ bis\ ba\ bcommunity\ bof\ bLinux\ bNerds" TecmintisacommunityofLinuxNerds4. Use the'\ n' option'- e' after the'\ n' line with the'\ n' line as a new line where encountered

$echo-e "Tecmint\ nis\ na\ ncommunity\ nof\ nLinux\ nNerds" Tecmint is a community of Linux Nerds5. Using the'\ t 'option'-e' followed by'\ t 'adds a horizontal tab between the spaces.

$echo-e "Tecmint\ tis\ ta\ tcommunity\ tof\ tLinux\ tNerds" Tecmint is a community of Linux Nerds6. You can also use the newline'\ n' and the horizontal tab'\ t' $echo-e "\ n\ tTecmint\ n\ tis\ n\ ta\ n\ tcommunity\ n\ tof\ n\ tLinux\ n\ tNerds" Tecmint is a community of Linux Nerds7. Use the'\ v 'option'-e' followed by'\ v'to add a vertical tab.

$echo-e "\ vTecmint\ vis\ va\ vcommunity\ vof\ vLinux\ vNerds" Tecmint is a community of Linux Nerds8. You can also use the newline'\ n' and the vertical tab'\ v'$echo-e "\ n\ vTecmint\ n\ vis\ n\ va\ n\ vcommunity\ n\ vof\ n\ vLinux\ n\ vNerds" Tecmint is a community of Linux Nerds Note: you can use two or more vertical tabs, horizontal tabs and line breaks as needed.

9. Use the'\ r 'option'-e' followed by'\ r'to specify the carriage return in the output. (LCTT translation note: characters at the beginning of a line are overwritten)

Echo-e "Tecmint\ ris a community of Linux Nerds" is a community of Linux Nerds10. Using the'\ c 'option'-e' followed by'\ c 'suppresses the characters following the output and does not end up with new lines.

That's all for $echo-e "Tecmint is a community\ cof Linux Nerds" Tecmint is a community @ tecmint:~$ "how to use the Linux echo command". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Tags: Output tabs tabs characters horizontal commands one line content at the same time text more knowledge spaces complex practical learned and then two variables dilemmas Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi Shulou Tech Info Redmi Microsoft Docker