Cloudkul Support

Commenting out multiple lines in bash

In order to comment out multiple lines in bash, we can use bourne shell’s operator “:” and a pair of single quotes.

Let’s take an example of a bash script

#!/bin/bash

echo "THIS COMMAND IS GONNA GET EXECUTED"

echo "UNLESS WE COMMENT OUT THE LINES"

echo "USE BASH SPECIAL CHARACTERS TO COMMENT OUT SCRIPT"

echo "GOODBYE"

Executing this script gives output as:

THIS COMMAND IS GONNA GET EXECUTED
UNLESS WE COMMENT OUT THE LINES
USE BASH SPECIAL CHARACTERS TO COMMENT OUT SCRIPT
GOODBYE

Now in order to comment out multiple lines, we place ” :  ‘ ” a line before the lines to be commented out and a  ” ‘ ” after the end of the lines as shown below:

#!/bin/bash

: '
echo "THIS COMMAND IS GONNA GET EXECUTED"

echo "UNLESS WE COMMENT OUT THE LINES"

echo "USE BASH SPECIAL CHARACTERS TO COMMENT OUT SCRIPT"
'

echo "GOODBYE"

After executing above shell script, output will be :

GOODBYE

Is this article is helpful?

People like and 0 people dislike.

If result is not found or irrelevant, Please contact us.

Submit your request

Start a Project




    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home