Questions – How can I print a newline as
\n in bash shell? How to use
\n in a shell script to print new line.
Issues – Echo newline in bash shell prints literal
\n but not new line. Printing literal
'\n' in a nested print new line in bash scripts.
Use the following command to print newline using \n in bash shell scripting. You have other options with the echo command. Read the complete tutorial.
printf “first line\nsecond line\n”
Uses of \n in Bash
\n (Line Feed) is used as a newline character for Unix-based systems. Below is a simple example to use a newline characters in bash shell scripts. Use one of the followings examples
String in double quote:
echo -e "This is First Line \nThis is Second Line"
String in single quote:
echo -e 'This is First Line \nThis is Second Line'
String with $ prefix:
echo $'This is First Line \nThis is Second Line'
Using printf command:
printf "This is First Line \nThis is Second Line"
You may also like our bash scripting tutorial.