by @CodingExample

How to print a new line in bash

Home » bash » How to print a new line in bash

In echo we need to use /n literal for printing a new line in bash.

Example:

echo "how\nare\nyou"

# how
# are
# you

If the above command doesn’t work you can try by adding a -e option to the echo.

echo -e "how\nare\nyou"

# how
# are
# you

Note: -e option enables the interpretation of backslash escapes.

Using printf

Similarly, we can use printf command instead of echo.

printf "What\nare\nyou\ndoing\n"

# What
# are
# you
# doing