How do I echo “-e”?

后端 未结 6 1833
被撕碎了的回忆
被撕碎了的回忆 2020-12-07 02:24

I want to echo a string that might contain the same parameters as echo. How can I do it without modifying the string?

For

6条回答
  •  情歌与酒
    2020-12-07 02:35

    Quote it:

    $ var="-e something"
    $ echo "$var"
    -e something
    

    If what you want is to get echo -e's behaviour (enable interpretation of backslash escapes), then you have to leave the $var reference without quotes:

    $ var="hi\nho"
    $ echo $var
    hi
    ho
    

    Or use eval:

    $ var="hi\nho"
    $ eval echo \${var}
    hi\nho
    
    $ var="-e hi\nho"
    $ eval echo \${var}
    hi
    ho
    

提交回复
热议问题