IT源码网

shell中echo输出换行的方法讲解

developer 2021年04月03日 程序员 164 0

echo要支持同C语言一样的\转义功能,只需要加上参数-e,如下所示:

[~]#echo "Hello world.\nHello sea"
Hello world.\nHello sea
[~]#echo -e "Hello world.\nHello sea"
Hello world.
Hello sea
[~]#

不加-e


看一下man的说明:

[~]#man echo | cat

ECHO(1)                          User Commands                         ECHO(1)


NAME
       echo - display a line of text


SYNOPSIS
       echo [OPTION]... [STRING]...


DESCRIPTION
       Echo the STRING(s) to standard output.


       -n     do not output the trailing newline


       -e     enable interpretation of backslash escapes


       -E     disable interpretation of backslash escapes (default)



       --help display this help and exit


       --version
              output version information and exit


       If -e is in effect, the following sequences are recognized:


       \0NNN  the character whose ASCII code is NNN (octal)


       \\     backslash


       \a     alert (BEL)


       \b     backspace


       \c     suppress trailing newline


       \f     form feed


       \n     new line


       \r     carriage return


       \t     horizontal tab


       \v     vertical tab


       NOTE: your shell may have its own version of echo, which usually super-
       sedes the version described here.  Please refer to your  shell’s  docu-
       mentation for details about the options it supports.

发布评论
IT源码网

微信公众号号:IT虾米 (左侧二维码扫一扫)欢迎添加!

Linux中定时任务crontab的使用讲解
你是第一个吃螃蟹的人
发表评论

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。