美文网首页生物信息学
echo是什么?shell的echo

echo是什么?shell的echo

作者: Amy_Cui | 来源:发表于2019-05-08 17:56 被阅读22次

    echo

    echo 是一个非常简单、直接的 Linux 命令:

    * 将 argument 送出至标准输出(STDOUT),通常就是在监视器(monitor)上输出。

    目录

    [TOC]

    查看echo帮助文档

    qmcui 18:05:08 ~
    $ man echo|cat
    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.
    
    AUTHOR
           Written by Brian Fox and Chet Ramey.
    
    REPORTING BUGS
           GNU coreutils online help: <http://www.gnu.org/software/coreutils/>
           Report echo translation bugs to <http://translationproject.org/team/>
    
    COPYRIGHT
           Copyright  ©  2016 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
           Full documentation at: <http://www.gnu.org/software/coreutils/echo>
           or available locally via: info '(coreutils) echo invocation'
    
    GNU coreutils 8.25                          February 2016                                    ECHO(1)
    
    

    举个简单例子

    $ echo
    
    $
    

    你会发现只有一个空白行,然后又回到 shell prompt 上了。

    这是因为echo会在输出的结束,默认输出一个换行。如果不想它输入换行符执行下面代码

    -n参数:取消行末之换行符号(与 -e 选项下的 \c 字符一样)

    qmcui 18:01:42 ~
    $ echo a
    a
    qmcui 18:01:58 ~
    $ echo -n a
    aqmcui 18:02:09 ~
    
    # 注意看区别
    

    -e :启用反斜线控制字符的转换(参考下表)

    qmcui 18:09:06 ~
    $ echo -e "a\tb\tc\nd\te\tf"
    a   b   c
    d   e   f
    
    qmcui 18:11:58 ~
    $ echo -e "\x61\x09\x62\x09\x63\x0a\x64\x09\x65\x09\x66"
    a   b   c
    d   e   f
    
    qmcui 18:12:05 ~
    $ echo -ne "a\tb\tc\nd\te\bf\a"
    a   b   c
    d   fqmcui 18:13:36 ~
    

    因为 e 字母后面是删除键(\b),因此输出结果就没有 e 了。
    在结束时听到一声铃向,那是 \a 的杰作﹗

    -E:关闭反斜线控制字符的转换(默认如此)

    输出功能

    $ A=B
    $ echo $A
    B
    $ echo $?
    0
    

    相关文章

      网友评论

        本文标题:echo是什么?shell的echo

        本文链接:https://www.haomeiwen.com/subject/gtmvoqtx.html