This article introduces to you how to use the newline character (\n) in Bash Shell. Let’s take a look at the specific content.
# Let’s first look at the command
Use the following command to print newlines using \n in a bash shell script.
printf “first line\nsecond line\n”
Usage of \n in bash
\ n (newline) is used as the newline character for Unix-based systems. Below is a simple example of using newlines in a bash shell script.
String in double quotes:
$ echo -e "This is First Line \nThis is Second Line"
String in single quotes:
$ echo -e 'This is First Line \nThis is Second Line'
String with $ prefix:
$ echo $'This is First Line \nThis is Second Line'
Use printf Command:
$ printf "This is First Line \nThis is Second Line"
This article is over here. For more exciting content, you can pay attention to the linux tutorial video column on the PHP Chinese website!
The above is the detailed content of How to use newline character (n) in Bash Shell. For more information, please follow other related articles on the PHP Chinese website!