How to Use a Bash Multiline Command
Bash multiline commands simply refer to commands that span more than one line. In this article, you will understand more on how bash reads/handles multiline commands. Also, at the end of this article, a handy software utility is introduced. This software utility will help you to read and access Linux files on a Windows PC without any stress.
Here you will find out:
- when you can use a bash multiline command
- how to print a multiline command
- when DiskInternals can help you
Are you ready? Let's read!
Long command lines and a bash multiline command
When your script contains long command lines, bash will continue to read the commands non-stop; if the cursor gets to the right-hand end, bash continues to the next line automatically. However, if you want bash to read your script line by line, then you must introduce a backslash (\) at the end of each line. Also, bash doesn’t support multiline comments; you have to write the comments serially.
Using a backslash \ or « to print a bash multiline command
If you’re writing a multiline command for bash, then you must add a backslash (\) at the end of each line. For multiline comments, you have to use the HereDoc « tag.
Multiline comments written serially:
Multiline comments written with «:
Bash will ignore everything in here.
Note: you must repeat the command you used in the first line at the end of the comment, and it should be written in ALL CAPS.
Write a comment with the hash mark (#)
Using # is the simplest way to write comments in bash. It is the most common way of writing comments.
The bash multiline command with “()”
Some users have confirmed that using brackets “()” can help to tell bash that it’s about to read a multiline command.
Using this blob, let's tell bash it's a multiline command:
Bash will now read the next lines by attaching a ">" for each new line.
Use Linux Reader to open Linux files
As promised, here's the software to use and open Linux files on a Windows PC. DiskInternals Linux Reader is an intuitive software app with an easy-to-understand interface. It displays all the Linux partitions present on a Windows PC and lets you access the important files that are saved inside. Linux Reader works with different file systems: Ext2/3/4, ReiserFS, Reiser4, HFS, HFS+, FAT, exFAT, NTFS, ReFS, UFS2, RomFS(reader), ZFS (preview only*), XFS (preview only*), Hikvision NAS and DVR (preview only*).