Home  >  Article  >  Operation and Maintenance  >  How to use linux echo command

How to use linux echo command

青灯夜游
青灯夜游Original
2021-07-26 16:27:1741514browse

In Linux, the echo command is used to output strings, the syntax is "echo [option] [output content]"; if there is no special meaning in the output content, the original content is output to the screen; if the output content has If there is a special meaning, the output prints its meaning.

How to use linux echo command

#The operating environment of this tutorial: CentOS 6 system, Dell G3 computer.

The echo command is similar to PHP’s echo command, both are used for string output.

The command format is as follows:

# echo [选项] [输出内容]

Options:

  • -e: supports backslash controlled character conversion (specific See Table 1)

  • -n: Cancel the newline symbol at the end of the line after output (the content will not wrap after output)

In fact, the echo command is very simple. If the output content of the command has no special meaning, the original content is output to the screen; if the output content has a special meaning, the meaning is printed.

[Example 1]

[root@localhost ~]# echo "c.biancheng.net"
#echo的内容就会打印到屏幕上
c.biancheng.net
[root@localhost ~]#

The echo command is that simple. Whatever content is output, the content will be printed on the screen.

[Example 2]

[root@localhost ~]# echo -n "c.biancheng.net"
c.biancheng.net[root@localhost ~]#
#如果加入了 "-n"选项,则在输出内容结束后,不会换行,直接显示新行的提示符

If the "-e" option is used in the echo command, control characters can be supported, as shown in the following table.

##\\Output\self\aOutput warning sound\bBackspace key, which is the left delete key\cSuppress the newline character at the end of the output line. Consistent with the "-n" option\eEsc key\fForm feed character \nLine break\rEnter key\tTab character, which is the Tab key\vVertical tab character\OnnnOutput characters according to the octal ASCII code table. Among them, 0 is the number 0, and nnn is a three-digit octal number \xhh Output characters according to the hexadecimal ASCH code table. Where hh is a two-digit hexadecimal number
Control characters Function
Related recommendations: "

Linux Video Tutorial"

The above is the detailed content of How to use linux echo command. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn