Facebook Twitter Instagram
    TecAdmin
    • Home
    • Ubuntu 20.04
      • Upgrade Ubuntu
      • Install Java
      • Install Node.js
      • Install Docker
      • Install LAMP Stack
    • Tutorials
      • AWS
      • Shell Scripting
      • Docker
      • Git
      • MongoDB
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    Home»Programming»Bash Shell»How to Use Newline character ( \n ) in Bash Shell

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

    RahulBy RahulNovember 14, 20141 Min ReadUpdated:April 20, 2018

    Questions – How can I print a newline as \n in bash shell? How to use \n in shell script to print new line.
    Issues – Echo newline in bash shell prints literal \n but not new line. Printing literal ‘\n’ in 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 to with echo command. Read 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 newline character in bash shell scripts. Use one of 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
    Previous ArticleHow to Prompt for User Input in Linux shell script
    Next Article How to change output Text color in Linux Shell

    Related Posts

    How to Backup Website to Amazon S3 using Shell Script

    Updated:March 24, 20222 Mins Read

    Bash Printf Command

    Updated:December 23, 20212 Mins Read

    Bash Sequence Expression (Define Range)

    Updated:January 12, 20222 Mins Read

    Bash Select Command (Create Menu in Shell Scripts)

    Updated:December 10, 20212 Mins Read

    Bash Break and Continue

    Updated:November 9, 20213 Mins Read

    Bash String Concatenate

    Updated:January 5, 20222 Mins Read

    Leave A Reply Cancel Reply

    Recent Posts
    • How to Enable / disable Firewall in Windows
    • How to Install JAVA on Ubuntu 22.04
    • Switching Display Manager in Ubuntu – GDM, LightDM & SDDM
    • Changing the Login Screen Background in Ubuntu 22.04 & 20.04
    • How To Install PHP (8.1, 7.4 or 5.6) on Ubuntu 22.04
    Facebook Twitter Instagram Pinterest
    © 2022 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

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