Home >Operation and Maintenance >Linux Operation and Maintenance >How to use newline character (\n) in Bash Shell

How to use newline character (\n) in Bash Shell

不言
不言Original
2019-03-22 15:02:4128635browse

This article introduces to you how to use the newline character (\n) in Bash Shell. Let’s take a look at the specific content.

How to use newline character (\n) in Bash Shell

# 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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn