Difference between 'echo' and 'echo -e'
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.
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?