echo “-e” doesn't print anything

后端 未结 10 2182
谎友^
谎友^ 2020-12-03 22:11

I\'m using GNU bash, version 3.00.15(1)-release (x86_64-redhat-linux-gnu). And this command:

echo \"-e\" 

doesn\'t print anything. I guess

相关标签:
10条回答
  • 2020-12-03 22:39

    This is a tough one ;)

    Usually you would use double dashes to tell the command that it should stop interpreting options, but echo will only output those:

    $ echo -- -e
    -- -e
    

    You can use -e itself to get around the problem:

    $ echo -e '\055e'
    -e
    

    Also, as others have pointed out, if you don't insist on using the bash builtin echo, your /bin/echo binary might be the GNU version of the tool (check the man page) and thus understand the POSIXLY_CORRECT environment variable:

    $ POSIXLY_CORRECT=1 /bin/echo -e
    -e
    
    0 讨论(0)
  • 2020-12-03 22:40

    You could cheat by doing

    echo "-e "
    

    That would be dash, e, space.

    Alternatively you can use the more complex, but more precise:

    echo -e \\\\x2De
    
    0 讨论(0)
  • 2020-12-03 22:41

    There may be a better way, but this works:

    printf -- "-e\n"
    
    0 讨论(0)
  • 2020-12-03 22:42
     
    [root@scintia mail]# POSIXLY_CORRECT=1; export POSIXLY_CORRECT
    [root@scintia mail]# /bin/echo "-e"
    -e
    [root@scintia mail]#
    
    0 讨论(0)
提交回复
热议问题