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
- 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
- How to Use Shell Script Sleep Command
- Bash: How to Check if the File Does Not Exist
- How to use bash get script directory in Linux
- 20 Examples of Bash Find Command
- Shell Script Cut: Basic You Need to Know
- Bash: How to Check if String Not Empty in Linux
- Linux: Sudo in Bash Scripts
- Linux: Bash Printf Examples
- Linux: Bash First Line
- Linux: A Bash Startup Script
- Linux: Write a Shell Script
- Shell Script: Replace String in File
- Bash and sh: is there any difference
- A Bash Dirname Command
- Linux: A Bash Source Command
- A Bash to Loop through Lines in File
- A Bash Nested Loop
- Use a Shell Script to Send an Email
- Using Bash to Write to a File
- About Bash Language
- Bash for Loop in One Line
- Learn about useful bash scripts
- About chaining bash commands
- About a bash export command
- Learn about a bash wait command
- Arch Linux install script
- About advanced bash scripting
- Learn about C shell script
- Learn about Korn shell scripting
- 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
- Copy command in shell scripts
- Install Oracle Database
- About a bash date command
- Guide in Pictures
- 5 Basic Shell Script Examples for Your First Script
- Bash Time Command on Linux
- How to Check Bash String Equality
- How to Use Linux Wait Command
- Bash: How to Loop Through Files in Directory
- 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
- Bash: how to split strings in Linux
- Hello World Script in Bash
- A Linux bin/bash Shell
- Linux: Bash String Ends With
- Linux: $0 in a Shell Script
- A crontab service shell script
- A Bash Multiline Command
- Linux: A Bash Linter
- A Bash Test Command
- A Bash Status of Last Command
- Linux: A Bash Basename Command
- AWK in a Bash Script
- Learn about systemd startup script
- Learn about a bash error code
- Using a bash tee command
- To run a shell script in Dockerfile
- About a bash UNTIL loop
- Using /usr/bin/env command
- Whether bash waits for command to finish
- Using bash if 0
- Learn to run Perl script in Linux
- Examples of using the Expect
- Shell script usage
- Here is everything you need to know about Bash for Windows
