How to print a new line in bash
To print a new line in bash, we need to use /n
literal in echo
command.
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