What is the difference between echo and echo -e?

And which quotes ("" or '') should be used with the echo command? i.e: echo "Print statement" or echo 'Print statement'?

Also, what are the available options that can be used along with echo?

  • 4
    What shell? echo -e is not defined by POSIX and probably varies by shell. – jordanm Mar 12 '15 at 18:28
  • Does this answer your question? unix.stackexchange.com/questions/65803/… – dhag Mar 12 '15 at 18:30
  • 2
    use man echo to read the manual for echo. – nanny Mar 12 '15 at 18:51
  • echo doesn't execute its arguments as commands, it just ... echos them – Anthon Mar 12 '15 at 20:21

echo by itself displays a line of text. It will take any thing within the following "..." two quotation marks, literally, and just print out as it is. However with echo -e you're making echo to enable interpret backslash escapes. So with this in mind here are some examples

INPUT: echo "abc\n def \nghi" 
OUTPUT:abc\n def \nghi

INPUT: echo -e "abc\n def \nghi"

Note: \n is new line, ie a carriage return. If you want to know what other sequences are recognized by echo -e type in man echo to your terminal.

  • 5
    echo is built-in in most shells. man echo will like document the echo standalone command instead. – Stéphane Chazelas Jul 24 '16 at 14:01
  • 1
    You're describing the behaviour of GNU echo or the GNU shell's echo when not in Unix conformance mode. Elsewhere, the behaviour will typically be different. – Stéphane Chazelas Jul 24 '16 at 14:03

In most of the SHELL echo cant take escape sequence ( \n \t ). Where as echo -e can

echo -e " This is \n an \t example"

Single quote and double quote are mostly for handling the interpolation issues. You may find more details here, Why is echo ignoring my quote characters?

  • That's the other way round. In most shells (ksh88, ksh93, pdksh, mksh, Bourne, zsh, dash, bash, and the sh of all Unix compliant systems, some of them like ksh93 or bash only in some environments) echo does expand escape sequences. An echo implementation that accepts -e is not POSIX compliant. – Stéphane Chazelas Jul 24 '16 at 13:59

Not the answer you're looking for? Browse other questions tagged or ask your own question.