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
     忽略\c后的字符,并且不加上换行符
       \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.

 

 

 

试验验证:

脚本  (倒计时60个数,每0.5秒一次  -w 按最大位数宽度显示)

#!/bin/bash

for i in $(seq -w 60 -1 0)
        do
                echo  "$i"
                sleep 0.5
        done

此时无任何转义字符,运行结果如下

[root@localhost test]# bash echo.sh 
60
59
58
57
56
55
54
53
^C
[root@localhost test]# 

 

1,echo -ne "$i"

  结果:不换行一次无间隔输出数字。

 

[root@localhost test]# bash echo.sh 
605958575655545352515049^C

 

2,echo -ne "\r"

  结果: 不换行每次在行首输出数字,实现倒计时。

[root@localhost test]# bash echo.sh 
56

3,echo -ne "\033[60G$i\r"

  结果:不换行在屏幕第60列输出倒计时,光标在行首

[root@localhost test]# bash echo.sh 
                                                           55

4,echo -ne "\033[60G$i"

  结果:不换行在屏幕第60列输出倒计时,光标在邻接数字后面

 

5,echo -ne "\033[60G$i\b"

  结果:不换行在屏幕第60列输出倒计时,光标在个位数上面

6,echo -ne "\033[60G$i\b\b"

  结果:不换行在屏幕第60列输出倒计时,光标在十位数上面

7,echo -ne "\033[60G$i\b\b"

  结果:不换行在屏幕第60列输出倒计时,光标在十位数前面

8,清屏,定位倒计时,此时屏幕中只有一个倒计时数字

#!/bin/bash

for i in $(seq -w 60 -1 0)
    do 
        clear
        echo -ne  "\033[25;100H$i"
        sleep 0.5
    done

 

 

 

其他选项:

\033[0m   关闭所有属性

\033[1m   设置高亮度

\033[4m   下划线

\033[5m   闪烁

\033[7m   反显

\033[8m   消隐

\033[30m — \033[37m   设置前景色

\033[40m — \033[47m   设置背景色

\033[nA   光标上移n行

\033[nB   光标下移n行

\033[nC   光标右移n行

\033[nD   光标左移n行

\033[y;xH设置光标位置

\033[2J   清屏

\033[K    清除从光标到行尾的内容

\033[s    保存光标位置

\033[u    恢复光标位置

\033[?25l   隐藏光标

\033[?25h   显示光标


echo 在位置变量过程中造环境的一个例子:
echo "echo $(echo \${1..15} |sed 's/1[0-5]/{&}/g')" > test.txt

[root@localhost test]# cat test.txt 
echo $1 $2 $3 $4 $5 $6 $7 $8 $9 ${10} ${11} ${12} ${13} ${14} ${15}
[root@localhost test]# bash test.txt {a..z}
a b c d e f g h i j k l m n o

或者

[root@localhost test]# seq -s " " 15 |sed 's/[0-9]\|1[0-5]/${&}/g'
${1} ${2} ${3} ${4} ${5} ${6} ${7} ${8} ${9} ${10} ${11} ${12} ${13} ${14} ${15}

 



 

posted @ 2017-08-21 18:29  Dothraki  阅读(239)  评论(0)    收藏  举报