25

What is the difference between echo and echo -e? Which quotes (" " or ' ')should be used with the echo command? ie: echo "Print statement" or echo 'Print statement'? Also, what are the available options that can be used along with echo?

closed as unclear what you're asking by jasonwryan, Anthon, John WH Smith, peterph, cuonglm Mar 13 '15 at 2:34

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 3
    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
33

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"
OUTPUT:abc
 def 
ghi

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.

  • 2
    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
  • 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
3

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.