How to insert a new line in Linux shell script? [duplicate] How to insert a new line in Linux shell script? [duplicate] bash bash

How to insert a new line in Linux shell script? [duplicate]


The simplest way to insert a new line between echo statements is to insert an echo without arguments, for example:

echo Create the snapshotsechoecho Snapshot created

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:

echo -e "Create the snapshots\n\nSnapshot created"

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 using printf:

printf "Create the snapshots\n\nSnapshot created\n"

This works more reliably in many systems, though it's not POSIX compliant. Notice that you must manually add a \n at the end, as printf doesn't append a newline automatically as echo does.


Use this echo statement

 echo -e "Hai\nHello\nTesting\n"

The output is

HaiHelloTesting


echo $'Create the snapshots\nSnapshot created\n'