This question already has an answer here:
- Echo newline in Bash prints literal \n 17 answers
I want to insert a new line between multiple echo statements. I have tried echo "hello\n"
, but it is not working. It is printing \n
. I want the desired output like this:
Create the snapshots
Snapshot created
Use this echo statement
The output is
You could use the printf(1) command, e.g. like
The
printf
command may accept arguments and needs a format control string similar (but not exactly the same) to the one for the standard C printf(3) function...The simplest way to insert a new line between
echo
statements is to insert anecho
without arguments, for example:That is,
echo
without any arguments will print a blank line.Another alternative to use a single
echo
statement with the-e
flag and embedded newline characters\n
:However, this is not portable, as the
-e
flag doesn't work consistently in all systems. A better way if you really want to do this is usingprintf
:This works more reliably in many systems, though it's not POSIX compliant. Notice that you must manually add a
\n
at the end, asprintf
doesn't append a newline automatically asecho
does.