echo “-e” doesn't print anything

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 this is because "-e" is one of a valid options of echo command because echo "-n" and echo "-E" (the other two options) also produce empty strings.

The question is how to escape the sequence "-e" for echo to get the natural output ("-e").


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'

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

The one true way to print any arbitrary string:

printf "%s" "$vars"

Need Your Help

Variable changes its value

c++ class opengl

I have a very strange problem with variables. After few calls in OPENGL render loop one variable changes its value (verticesSize) without any reasons while the 2nd variable(verticesSize2) not...

JS or Jquery create unique span ID

javascript jquery html

I'm creating a li item with a span inside. I've built an onclick function in the span to grab the parent li's ID to pass into a JSON get request. I'm unsure of how to create a unique ID and read it...