echo屏幕显示一段文字

版权声明:qq:1263351411 https://blog.csdn.net/u013008795/article/details/88778885

3.10 echo屏幕显示一段文字

3.10.1语法

echo [-neE] [arg …]

可以使用echo查看某个系统变量的值:
例如:
【echo ${PATH}】
在这里插入图片描述
查看当前shell
【echo ${SHELL}】
在这里插入图片描述
3.10.2 常用参数
【-n】表示不换行输出(echo默认打印前会输出一个换行符号,如果使用-n参数,则不会换行输出)
例如:
在这里插入图片描述
【-e】转译字符,如果输出的字符中带有特殊意义的字符,那么使用-e则可以转译输出:
例如:
在这里插入图片描述
在打印字符中显示颜色
例如:【echo -e “\033[1;37;41mHello\033[0m,world.”】
在这里插入图片描述
其中:

  • 【\033】表示ctrl按键
  • 【\033[】表示开始使用颜色修饰字体
  • 【1:37:41m】中 1表示只退的宽度
    • 37中的3表示修饰字体本身颜色,7代表白色
    • 41中的4表示修饰字体的背景颜色1表示使用红色
      注意:修饰前景色用3表示,修饰背景色用4表示,只有一位数表示字体显示格式
  • 【\033[0m】表示修改字体的结束位置

3.10.3 附加

相关命令:printf打印字符,与echo不同的是默认不首位打印换行符
例如:

‘’:强引用,不完成变量替换
“”:弱引用,可以完成变量替换
``:命令替换
$():命令替换

man echo
NAME
       echo - display a line of text

SYNOPSIS
       echo [SHORT-OPTION]... [STRING]...
       echo LONG-OPTION

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:

       \\     backslash

       \a     alert (BEL)

       \b     backspace

       \c     produce no further output

       \e     escape

       \f     form feed

       \n     new line

       \r     carriage return

ECHO(1)                          User Commands                         ECHO(1)

NAME
       echo - display a line of text

SYNOPSIS
       echo [SHORT-OPTION]... [STRING]...
       echo LONG-OPTION

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:

       \\     backslash

       \a     alert (BEL)

       \b     backspace

       \c     produce no further output

       \e     escape

       \f     form feed

       \n     new line

       \r     carriage return

       \t     horizontal tab

       \v     vertical tab

       \0NNN  byte with octal value NNN (1 to 3 digits)

       \xHH   byte with hexadecimal value HH (1 to 2 digits)

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

猜你喜欢

转载自blog.csdn.net/u013008795/article/details/88778885