echo linux命令

Linux echo command is used to display a line of text on the screen. This is done by echoing the string to the standard output.

Linux echo命令用于在屏幕上显示一行文本。 这是通过将字符串回显到标准输出来完成的。

Linux echo命令 (Linux echo Command)

Let’s see how the echo command is described by the Linux man page. The man page can be accessed by typing the following command:

让我们看看Linux手册页如何描述echo命令。 可以通过键入以下命令来访问手册页:

echo man page command

回声手册页命令

The following will be displayed as output. Let’s understand the help page part-by-part.

以下将显示为输出。 让我们逐部分地了解帮助页面。

Linux echo help output

Linux echo帮助输出

Linux echo命令语法 (Linux echo Command Syntax)

$ echo [OPTION]... [STRING]...

Linux echo命令示例 (Linux echo Command Examples)

echo command output

回显命令输出

There is no change in the output if the text to be displayed is written without double-quotes. However, it’s good practice to use double-quotes to emphasize the string, as shown in the example above.

如果要显示的文本不带双引号,则输出不会发生变化。 但是,优良作法是使用双引号来强调字符串,如上面的示例所示。

Linux echo Command Example

Linux echo命令示例

Linux echo命令选项 (Linux echo Command Options)

Linux echo Command Options can be used to modify the output of the command as per the user. Let’s go through them one-by-one.

Linux echo命令选项可用于根据用户修改命令的输出。 让我们一一讲解它们。

  • -n option can be used to remove the '\n' (newline character) from the output. By default, echo includes '\n' at the end of every string it outputs.

    Linux echo -n option example

    In the example above, since the newline character at the end of the output is omitted, the terminal prompts the user for input in the same line as the output.

    -n选项可用于从输出中删除'\n' (换行符)。 默认情况下,echo在输出的每个字符串的末尾都包含'\n'

    Linux echo -n选项示例

    在上面的示例中,由于省略了输出末尾的换行符,因此终端会提示用户在与输出相同的行中进行输入。

  • -e option enables the terminal to recognize escape sequences in the inputted string.

    The following sequences are recognized, as described in the Linux man page.

    1. ‘\\’ backslash character
    2. ‘\a’ alert (BEL): A sound is played when this character is encountered in an inputted string.
    3. ‘\b’ backspace: Backspace is triggered when this character is encountered in a string. Hence, the character before '\b' is removed from the output, as shown below.
    4. Linux echo backspace example

    5. ‘\c’ produce no further output: All characters after '\c' in a string are omitted from the output. Note that the terminal prompts for input in the same line as the output. This is because '\n' – newline character is also removed from the output.
    6. Linux echo stop output example

    7. ‘\n’ newline: When encountered in a string, this escape sequence triggers the creation of a new line. As a result, characters after '\n' are outputted in a new line.
    8. echo newline example

    9. ‘\r’ carriage return: Characters before '\r' in a string are omitted from the output, as shown in the example below.
    10. Linux echo carriage return example

    11. ‘\t’ horizontal tab: A tab space is created in the output, wherever '\t' appears in the string.
    12. Linux echo tab example

    13. ‘\v’ vertical tab: A vertical tab space is created in the output, wherever '\v' appears in the string.
    14. Linux echo vertical tab example

    -e选项使终端能够识别输入字符串中的转义序列。

    如Linux手册页中所述,可以识别以下序列。

    1. '\\'反斜杠字符
    2. '\ a'警报(BEL) :在输入的字符串中遇到此字符时会播放声音。
    3. '\ b'退格键 :在字符串中遇到此字符时将触发退格键。 因此,将从输出中删除'\b'之前的字符,如下所示。
    4. Linux回声退格示例

    5. '\ c'不再产生输出 :字符串中'\c'之后'\c'所有字符都将从输出中省略。 请注意,终端在与输出相同的行中提示输入。 这是因为'\n' n'–换行符也会从输出中删除。
    6. Linux回声停止输出示例

    7. '\ n'newline :在字符串中遇到时,此转义序列触发创建新行。 结果, '\n'之后'\n'字符将在新行中输出。
    8. 回声换行示例

    9. '\ r'回车 :从输出中省略字符串中'\r'之前的字符,如下例所示。
    10. Linux回声回车示例

    11. '\ t'水平制表符 :在字符串中出现'\t'任何位置,都会在输出中创建一个制表符空间。
    12. Linux echo选项卡示例

    13. '\ v'垂直制表符 :在字符串中出现'\v'任何位置,都会在输出中创建垂直制表符空间。
    14. Linux echo垂直制表符示例

  • -E option when used, disables the recognition of escape sequence in strings. This option is enabled by default.使用-E选项时,将禁用字符串中转义序列的识别。 默认情况下启用此选项。
  • –version and –help display version information and help window respectively and exit afterwards.–version–help分别显示版本信息和帮助窗口,然后退出。

Linux echo命令高级示例 (Linux echo Command Advanced Examples)

  1. Linux echo command is used with the wildcard character '*' to display the names of all files present in the current directory.

    Linux echo filenames example

    It can also be used in this way to display selected files/folders with certain lowercase/uppercase characters present in their names.

    In the example below, only files in the current directory, which have “D” as the initial letter and “s” as the last letter of their name, are displayed as output.

    Linux echo selected filenames example

    Linux echo命令与通配符'*'一起使用,以显示当前目录中存在的所有文件的名称。

    Linux echo文件名示例

    它也可以这种方式用于显示所选文件/文件夹,其名称中包含某些小写/大写字符。

    在下面的示例中,仅将当前目录中名称为首字母“ D”,名称最后一个字母为“ s”的文件显示为输出。

    Linux echo选择的文件名示例

  2. Linux echo command can be used to perform basic arithmetic operations and display the result as output. This is done by enclosing the mathematical part within (( )) preceded by a $ symbol.Linux echo命令可用于执行基本的算术运算并将结果显示为输出。 这是通过将数学部分放在(( ))内并加$符号来完成的。
  3. Linux echo math operations example

    Linux echo Math操作示例

  4. We can use echo command to display user-defined variables or even environment variables.

    echo variable value display example

    我们可以使用echo命令显示用户定义的变量甚至环境变量。

    回声变量值显示示例

结论 (Conclusion)

Linux echo is a simple, fundamental command that displays a line of text as output. The output can be modified by using the available options along with the command. Among other uses, it can display filenames and values of both user-defined and system variables as well as give the result to some basic arithmetic.

Linux echo是一个简单的基本命令,它将一行文本显示为输出。 可以通过使用可用选项和命令来修改输出。 除其他用途外,它还可以显示用户定义和系统变量的文件名和值,并将结果提供给一些基本的算术运算。

翻译自: https://www.journaldev.com/30389/linux-echo-command-examples

echo linux命令

echo linux命令_Linux echo命令示例相关推荐

  1. linux tee命令_Linux tee命令示例

    linux tee命令 In this article, we shall go through the tee command in Linux. This is commonly used to ...

  2. linux sed命令_Linux sed命令用法与示例

    linux sed命令 Sed, short for Stream EDitor, is a command that is used to perform text transformations ...

  3. linux date命令_Linux date命令示例

    linux date命令 Unix/Linux date command is a command used for displaying the system's date and time. In ...

  4. linux su命令_Linux Su命令示例教程

    linux su命令 The su short for substitute super user command using to change currently logged user.  Th ...

  5. linux tail 命令_Linux tail命令示例

    linux tail 命令 Linux tail command outputs the last part of the files. There is an option to keep the ...

  6. checksum linux 命令_linux常用命令总结

    一.find命令 作用:查找文件 [root@server ~]# find / -name elasticsearch /var/log/elasticsearch /var/run/elastic ...

  7. linux zx命令_linux常用命令小结

    查询操作系统类型 cat /etc/issue cat /etc/redhat-release 查询操作系统内核版本 cat /proc/version 查询服务器信息 uname -a 查询服务器n ...

  8. linux中wc命令_Linux wc命令–文件中字,行,字符的计数

    linux中wc命令 Linux wc command is used to count the number of words, lines, and characters in a file. T ...

  9. linux 指令tftp传输文件_tftp命令_Linux tftp 命令用法详解:在本机和tftp服务器之间使用TFTP协议传输文件...

    tftp命令用在本机和tftp服务器之间使用TFTP协议传输文件. TFTP是用来下载远程文件的最简单网络协议,它其于UDP协议而实现.嵌入式linux的tftp开发环境包括两个方面:一是linux服 ...

最新文章

  1. eclipse中的git安装与使用
  2. 横向循环焦点图片展示_多光子显微镜成像技术之十二:多光子显微镜中的焦点深度扩展方法...
  3. CI框架--加载静态内容
  4. mysql约束_不是吧,阿Sir,MySQL约束你竟然还不懂!
  5. jQuery基础部分笔记
  6. cdn回源php_别让CDN的回源把你的服务器拖垮,采用正确的回源策略
  7. 麦轮平台的速度分解与合成
  8. python内置模块在哪个文件夹_用 Python 内置模块处理 ini 配置文件
  9. OpenJudge 2990:符号三角形 解析报告
  10. 纽约出租车计费问题:一个简单的线性模型
  11. C3P0与DBCP数据库连接池的区别,阿里的Druid数据源配置入门
  12. servlet篇 之servlet实现
  13. Facebook频繁封号,如何解封?
  14. Linux环境下进行本地Blast比对——操作流程
  15. 一招惊艳所有人,HTML制作网页成绩表
  16. 七牛上传图片初探 开始上传 暂停上传 继续上传
  17. cf修改游戏客户端是什么意思_cf封号原因是非法篡改游戏客户端是什么意思
  18. 我问了10个博客专家好友,原来他们都在用这些高效率软件
  19. earlier的意思_earlier和before都有之前的意思?有什么区别吗
  20. 夜神模拟器 版本下载

热门文章

  1. 关于 xib 的使用
  2. Ajax Post请求实例
  3. LintCode: Two Sum
  4. 软件开发再编写过程中,要尽可能地让开发者再后来可以很容易地找到软件的编写逻辑和思路结构。这才是我们需要追求的。...
  5. 排序1+3:基数排序(RadixSort),希尔排序(ShellSort)和快速排序(QuickSort)
  6. 2005这一年不堪回首的日子
  7. BZOJ.4500.矩阵(差分约束 SPFA判负环 / 带权并查集)
  8. ETL第一篇(Kettle Spoon) 初遇
  9. C#遍历文件夹下所有文件
  10. 收藏个支持进度条与文件拖拽上传的js File Uploader