How do I echo “-e”?

后端 未结 6 1828
被撕碎了的回忆
被撕碎了的回忆 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:49

    Since we're using bash, another alternative to echo is to simply cat a "here string":

    $ var="-e something"
    $ cat <<< "$var"
    -e something
    $ var="-e"
    $ cat <<< "$var"
    -e
    $ 
    

    printf-based solutions will almost certainly be more portable though.

提交回复
热议问题