Facebook Twitter Instagram
    TecAdmin
    • Home
    • FeedBack
    • Submit Article
    • About Us
    Facebook 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.

    Advertisement

    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

    10 Most Popular Linux Shells

    10 Most Popular Open Source Linux Shells

    How to Create Bash Aliases with Arguments

    How to Create Bash Aliases with Parameters

    Checking If a Command Succeeded in Bash Using the `$?` Special Variable

    Add A Comment

    Leave A Reply Cancel Reply

    Advertisement
    Recent Posts
    • 11 Practical Example of cat Command in Linux
    • sleep Command in Linux with Examples
    • 20 Basic Linux Commands for the Beginners (Recommended)
    • tail Command in Linux with Examples
    • What is a Orphan Process in Unix/Linux
    Facebook Twitter Instagram Pinterest
    © 2023 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

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