echo命令用于在shell中打印shell变量的值,或者直接输出指定的字符串。

选项

-e:激活转义字符。 使用-e选项时,若字符串中出现以下字符,则特别加以处理,而不会将它当成一般文字输出:
\a 发出警告声;
\b 删除前一个字符;
\c 最后不加上换行符号;
\f 换行但光标仍旧停留在原来的位置;
\n 换行且光标移至行首;
\r 光标移至行首,但不换行;
\t 插入tab;
\v 与\f相同;
\\ 插入\字符;
\nnn 插入nnn(八进制)所代表的ASCII字符;

  

输出颜色

文字色 \e[1;31m 将颜色设置为红色 \e[0m 将颜色重新置

颜色码:重置=0,黑色=30,红色=31,绿色=32,黄色=33,蓝色=34,洋红=35,青色=36,白色=37

eg:

[root@layzj022301 ~]# echo -e "\e[1;31mThis is red text\e[0m"
This is red text
[root@layzj022301 ~]#
[root@layzj022301 ~]# echo -e "\e[1;32mThis is green text\e[0m"
This is green text
[root@layzj022301 ~]# echo -e "\e[1;33mThis is yellow text\e[0m"
This is yellow text
[root@layzj022301 ~]# echo -e "\e[1;34mThis is blue text\e[0m"
This is blue text
[root@layzj022301 ~]# echo -e "\e[1;35mThis is carmine text\e[0m"
This is carmine text
[root@layzj022301 ~]# echo -e "\e[1;36mThis is cyan text\e[0m"
This is cyan text
[root@layzj022301 ~]# echo -e "\e[1;37mThis is white text\e[0m"
This is white text
[root@layzj022301 ~]#

  

背景色

颜色码:重置=0,黑色=40,红色=41,绿色=42,黄色=43,蓝色=44,洋红=45,青色=46,白色=47

eg:

[root@layzj022301 ~]# echo -e "\e[1;47mThis is red text\e[0m"
This is red text
[root@layzj022301 ~]# echo -e "\e[1;46mThis is green text\e[0m"
This is green text
[root@layzj022301 ~]# echo -e "\e[1;45mThis is yellow text\e[0m"
This is yellow text
[root@layzj022301 ~]# echo -e "\e[1;44mThis is blue text\e[0m"
This is blue text
[root@layzj022301 ~]# echo -e "\e[1;43mThis is carmine text\e[0m"
This is carmine text
[root@layzj022301 ~]# echo -e "\e[1;42mThis is cyan text\e[0m"
This is cyan text
[root@layzj022301 ~]# echo -e "\e[1;41mThis is white text\e[0m"
This is white text
[root@layzj022301 ~]#

  

文字闪动

[root@layzj022301 ~]# echo -e "\033[37;31;5mHello This Wenderful Shell~~~\033[39;49;0m"
Hello This Wenderful Shell~~~
[root@layzj022301 ~]#

  

man echo

[root@layzj022301 ~]# man echo
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 documenta-
tion for details about the options it supports. AUTHOR
Written by Brian Fox and Chet Ramey. REPORTING BUGS
Report echo bugs to bug-coreutils@gnu.org
GNU coreutils home page: <http://www.gnu.org/software/coreutils/>
General help using GNU software: <http://www.gnu.org/gethelp/>
Report echo translation bugs to <http://translationproject.org/team/> COPYRIGHT
Copyright © 2010 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. SEE ALSO
The full documentation for echo is maintained as a Texinfo manual. If the info and echo programs are properly installed at your site, the com-
mand info coreutils 'echo invocation' should give you access to the complete manual. GNU coreutils 8.4 June 2014 ECHO(1)

  

echo 命令详解的更多相关文章

  1. Linux CAT与ECHO命令详解 <<EOF EOF

    Linux CAT与ECHO命令详解 cat命令是Linux下的一个文本输出命令,通常是用于观看某个文件的内容的: cat主要有三大功能: .一次显示整个文件. $ cat filename .从键盘 ...

  2. Linux CAT与ECHO命令详解

    Linux CAT与ECHO命令详解 cat命令是Linux下的一个文本输出命令,通常是用于观看某个文件的内容的: cat主要有三大功能: 1.一次显示整个文件. $ cat filename 2.从 ...

  3. (转)shell命令:echo命令详解

    shell命令:echo命令详解 原文:https://www.cnblogs.com/xyz0601/archive/2015/04/23/4450736.html 功能说明:显示文字. 语 法:e ...

  4. echo命令详解

    echo: echo [-neE] [arg ...] echo会将输入的字符串送往标准输出.输出的字符串间以空白字符隔开, 并在最后加上换行号. Options: -n 不在最后自动换行 -e 使用 ...

  5. linux下echo命令详解(转)

      linux的echo命令, 在shell编程中极为常用, 在终端下打印变量value的时候也是常常用到的, 因此有必要了解下echo的用法 echo命令的功能是在显示器上显示一段文字,一般起到一个 ...

  6. shell命令:echo命令详解

    功能说明:显示文字. 语 法:echo [-ne][字符串] / echo [--help][--version] 补充说明:echo会将输入的字符串送往标准输出.输出的字符串间以空白字符隔开, 并在 ...

  7. Shell命令:echo 命令详解

    http://blog.chinaunix.net/uid-27124799-id-3383327.html # echo命令介绍 功能说明:显示文字. 语 法:echo [-ne][字符串] / e ...

  8. DOS中的ECHO命令详解

    1. 作为控制批处理命令在执行时是否显示命令行自身的开关  格式:ECHO [ON|OFF]  如果想关闭“ECHO OFF”命令行自身的显示,则需要在该命令行前加上“@”.  2. 显示当前ECHO ...

  9. linux中echo命令详解

    linux的echo命令, 在shell编程中极为常用, 在终端下打印变量value的时候也是常常用到的, 因此有必要了解下echo的用法 echo命令的功能是在显示器上显示一段文字,一般起到一个提示 ...

随机推荐

  1. Mac OSX上卸载Anaconda

    方案一 anaconda安装程序在~/.bash_profile脚本中新添加了一行,将anaconda bin目录添加到了$PATH环境变量中.所以你只需要删除anaconda目录,但是最好也从安装脚 ...

  2. 005-docker-镜像使用、拉取、运行、创建、打tag

    当运行容器时,使用的镜像如果在本地中不存在,docker 就会自动从 docker 镜像仓库中下载,默认是从 Docker Hub 公共镜像源下载. 1.列出所有本地镜像 docker images ...

  3. axios post、get 请求参数和headers配置

    axios.post("http://xxx.com/xxx/xxx/xxx?", { 'queslistid':this.kemuid }, { headers: {'token ...

  4. CMDB资产管理

    .传统运维和自动化运维的区别: 传统运维: 1.项目上线: a.产品经理前期调研(需求分析) b.和开发进行评审 c.开发进行开发 d.测试进行测试 e.交给运维人员进行上线 上线: 直接将代码交给运 ...

  5. 分组加密的四种模式(ECB、CBC、CFB、OFB)

    加密一般分为对称加密(Symmetric Key Encryption)和非对称加密(Asymmetric Key Encryption).对称加密又分为分组加密和序列密码.分组密码,也叫块加密(bl ...

  6. keras学习简单线性回归【1】

    转自:https://morvanzhou.github.io/tutorials/machine-learning/keras/2-1-regressor/ 总的代码的过程就是: 1.导入模块+创建 ...

  7. 关于RTSP-Over-HTTP

    --------------------更新2018.07.10------------------- myRtspClient-1.3.0开始支持RTSP-Over-HTTP ----------- ...

  8. [Java in NetBeans] Lesson 11. While Loops

    这个课程的参考视频和图片来自youtube. 主要学到的知识点有:(the same use in C/C++) 1. while loop while(i < max){} will keep ...

  9. websocket协议的思考

    同过wireshark抓包,都是TCP的连接,省了好多的HTTP的头部请求 Ping Pong,TCP keep alive,双方没有数据来往的时候,通过发空白报文,侦测的报文来决定看这个链接是否还存 ...

  10. Java Selenium - 元素定位(一)

    一,单个元素对象定位 Webdriver通过findElement() , findElements()等方法调用By对象来定位和查询元素 , findElement()返回一个元素对象,否则抛出异常 ...