Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

echo "-e" doesn't print anything

Tags:

bash

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").

like image 456
wheleph Avatar asked Nov 26 '08 11:11

wheleph


People also ask

How to print\ n in bash?

Printing Newline in Bash The most common way is to use the echo command. However, the printf command also works fine. Using the backslash character for newline “\n” is the conventional way. However, it's also possible to denote newlines using the “$” sign.

How to give new line in echo command?

On the command line, press Shift + Enter to do the line break inside the string.

How to go to next line in bash?

From the bash manual: The backslash character '\' may be used to remove any special meaning for the next character read and for line continuation.


1 Answers

The one true way to print any arbitrary string:

printf "%s" "$vars"
like image 80
nanaya Avatar answered Sep 28 '22 05:09

nanaya