How do I echo “-e”?

后端 未结 6 1830
被撕碎了的回忆
被撕碎了的回忆 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条回答
  •  萌比男神i
    2020-12-07 02:48

    Try the following:

    $ env POSIXLY_CORRECT=1 echo -e
    -e
    

    Due to shell aliases and built-in echo command, using an unadorned echo interactively or in a script may get you different functionality than that described here. Invoke it via env (i.e., env echo ...) to avoid interference from the shell.

    The environment variable POSIXLY_CORRECT was introduced to allow the user to force the standards-compliant behaviour. See: POSIX at Wikipedia.

    Or use printf:

    $ printf '%s\n' "$var"
    

    Source: Why is bash swallowing -e in the front of an array at stackoverflow SE

提交回复
热议问题