How to Get a New Line in Shell Script
Newline is used to identify the end of a line in a script to mark the beginning of a new line, referred to as line break or line feed. Just as you will put the br tag in HTML scripts to force the subsequent characters into a new line, that’s what newline means in shell scripts.
Here you will find out:
- how to skip from one line to another
- different methods of how to use a new line
- when DiskInternals can help you
Are you ready? Let's read!
The simplest way to use a new line in a shell script
There are quite a couple of ways to insert a new line in a shell script. However, here are some of the simplest methods to do this:
The script above will print
When you write the “echo” command without attaching any argument, it prints a blank line.
Here’s another way to do this:
This will print:
The most used newline character
If you don’t want to use echo repeatedly to create new lines in your shell script, then you can use the \n character. The \n is a newline character for Unix-based systems; it helps to push the commands that come after it onto a new line. An example is below.
Using printf command in a shell script
It is possible to use printf in place of echo. Printf is the alternative way to insert newlines in shell scripts instead of using echo –e. This is because the -e flag isn’t compatible with all systems.
Printf is compatible with quite many systems, and it is more reliable; however, it is not in compliance with POSIX. Also, you will need to add \n at the end, because printf doesn't automatically add new lines as echo does.
For example:
What to do to open Linux files from Windows?
Typically, you cannot open Linux files from Windows, but sometimes you may be in urgent need to access the files in your Ext2/3/4 partitions. In such scenarios, DiskInternals Linux Reader can be of great help. This software tool helps you to access Linux files from a Windows PC. It is a freeware program with an intuitive interface. Using DiskInternals Linux Reader, you can view and access Linux files, but you cannot edit them directly.
Steps to read Linux files on Windows
First, you need to install DiskInternals Linux Reader on your PC.
Launch the app to view all the Linux partitions files.
Choose the partition where you saved the Linux files.
View all the Linux files; Linux Reader can read media files, documents, and any other files on the file systems (Ext2/3/4, ReiserFS, Reiser4, HFS, HFS+, FAT, exFAT, NTFS, ReFS). To view a file, right-click on the file and select “Preview in New Window”.


Now copy the files from the Linux partition to Windows partitions and start editing.
Related articles
- About a bash date command
- How to Access Linux Ext2 or Ext3 on Windows
- How to Access Ext4 from Windows
- How to Mount Ext4 on Windows for Free
- Mount Linux Drive on Windows for Free
- Bash Script: All You Need to Know
- An Algorithm: How to Create Bash While Loop
- Linux Shell: What You Need to Know at First
- 5 Basic Shell Script Examples for Your First Script
- Bash: How to Check if the File Does Not Exist
- Bash Time Command on Linux
- How to use bash get script directory in Linux
- How to Check Bash String Equality
- How to Use Linux Wait Command
- Bash: How to Loop Through Files in Directory
- 20 Examples of Bash Find Command
- Bash Cat Command in Examples
- Bash Script SSH: How to Use It
- Bash: A Script For User Input
- Linux ZSH: the basic you need to know
- Basic of Grep in Linux Shell Script
- Shell Script Cut: Basic You Need to Know
- Bash: How to Check if String Not Empty in Linux
- Bash: how to split strings in Linux
- Linux: Sudo in Bash Scripts
- Hello World Script in Bash
- A Linux bin/bash Shell
- Linux: Bash String Ends With
- Linux: Bash Printf Examples
- Linux: Bash First Line
- Linux: $0 in a Shell Script
- Linux: A Bash Startup Script
- Linux: Write a Shell Script
- Shell Script: Replace String in File
- A crontab service shell script
- Bash and sh: is there any difference
- A Bash Dirname Command
- Linux: A Bash Source Command
- A Bash to Loop through Lines in File
- Linux: A Bash Linter
- A Bash Nested Loop
- A Bash Test Command
- Use a Shell Script to Send an Email
- A Bash Status of Last Command
- Linux: A Bash Basename Command
- Using Bash to Write to a File
- About Bash Language
- Bash for Loop in One Line
- AWK in a Bash Script
- Learn about useful bash scripts
- Learn about systemd startup script
- About chaining bash commands
- Learn about a bash error code
- Using a bash tee command
- About a bash export command
- Learn about a bash wait command
- Arch Linux install script
- About advanced bash scripting
- To run a shell script in Dockerfile
- About a bash UNTIL loop
- Learn about C shell script
- Learn about Korn shell scripting
- Using /usr/bin/env command
- Whether bash waits for command to finish
- Using bash if 0
- Using && in an IF statement in bash
- If you want to run shell script in background
- The disk you inserted was not readable by this computer error
- Learn about SFTP in bash scripting
- Learn to run Perl script in Linux
- Examples of using the Expect
- Copy command in shell scripts
- Shell script usage
- Install Oracle Database
- Here is everything you need to know about Bash for Windows
- Guide in Pictures
- How to Use Shell Script Sleep Command
- A Bash Multiline Command
