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

不言
Release: 2019-03-22 15:02:41
Original
28582 people have browsed it

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”
Copy after login

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"
Copy after login

String in single quotes:

$ echo -e 'This is First Line \nThis is Second Line'
Copy after login

String with $ prefix:

$ echo $'This is First Line \nThis is Second Line'
Copy after login

Use printf Command:

$ printf "This is First Line \nThis is Second Line"
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template