The bash echo
command isn't using the escaped characters like "\n" and "\t"
echo "This is test string\nAnd this is next line"
For the above input it displays
This is test string\nAnd this is next line
So how do I print on the next line?
The bash echo
command isn't using the escaped characters like "\n" and "\t"
echo "This is test string\nAnd this is next line"
For the above input it displays
This is test string\nAnd this is next line
So how do I print on the next line?
ANSI-C Quoting
The
echo
command varies quite a bit -- some implementations interpret escape characters in their arguments, some don't unless you add the-e
option... some will print "-e" as part of their output if you try to use it as an option. If you want predictable results when doing anything nontrivial, useprintf
instead (note that you must explicitly include the ending newline):I learned this lesson the hard way, when OS X v10.5 came with a version of bash with a builtin
echo
that broke a bunch of my scripts that'd worked just fine under v10.4...You can use
echo -e
or you can use theshopt
built-in thusly at the beginning of your script:You need
echo -e
if you want escaped characters to be expanded: