echo屏幕显示一段文字

本文详细介绍了Linux中的echo命令,包括其基本语法、常用参数和如何显示彩色文字。通过示例展示了如何使用echo查看系统变量值、不换行输出以及利用转译字符实现颜色显示。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值