Skip to content
Advertisement

Echo -e escape sequences?

After days of researching I still don’t understand why :

echo -e anb 

gives me an output of : anb

While

echo -e 'anb'   -----> Gives me an output of 

 a
 b

I understand that echo -e activates the escape sequence , So it should work on the first example but it doesn’t .. I’m lost. I tried same commands in Ubuntu and OpenSuse .. both , same results . Any Help ?

Advertisement

Answer

The shell interprets the character when the character is not quoted, and the shell (normally) interprets it differently than the echo command.

echo -e anb

In the above, the shell interprets n as n, because the characters are not in quotes. So the shell passes the characters anb to the echo command.

echo -e 'anb'

In the above, the shell passes the exact characters anb to the echo command, because the single quotes tell the shell not to interpret the .

Note that bash supports a form of quoting that interprets ANSI C escapes directly:

echo $'anb'
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement