Facebook X (Twitter) Instagram
    TecAdmin
    • Home
    • FeedBack
    • Submit Article
    • About Us
    Facebook X (Twitter) Instagram
    TecAdmin
    You are at:Home»Programming»Bash Shell»How to Use Newline character ( \n ) in Bash Shell

    How to Use Newline character ( \n ) in Bash Shell

    By RahulOctober 25, 20221 Min Read

    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.

    Command:


    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.

    bash newline script
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp

    Related Posts

    An Introduction to Bash Variables

    An Introduction to Bash Variables

    Bash LOCAL and GLOBAL Variables

    Bash LOCAL and GLOBAL Variables

    Bash Script to Reverse a Number

    Add A Comment

    Leave A Reply Cancel Reply

    Advertisement
    Recent Posts
    • Difference Between Full Virtualization vs Paravirtualization
    • Virtualization vs. Containerization: A Comparative Analysis
    • Using .env Files in Django
    • Using .env File in FastAPI
    • Setting Up Email Notifications for Django Error Reporting
    Facebook X (Twitter) Instagram Pinterest
    © 2023 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.