Shell Comments

From Linux Shell Scripting Tutorial - A Beginner's handbook
Jump to: navigation, search
← ShebangHomeSetting up permissions on a script →

Take look at the following shell script:

#!/bin/bash
# A Simple Shell Script To Get Linux Network Information
# Vivek Gite - 30/Aug/2009
echo "Current date : $(date) @ $(hostname)"
echo "Network configuration"
/sbin/ifconfig

The first line is called a shebang or a "bang" line. The following are the next two lines of the program:

# A Simple Shell Script To Get Linux Network Information
# Vivek Gite - 30/Aug/2009
  • A word or line beginning with # causes that word and all remaining characters on that line to be ignored.
  • These lines aren't statements for the bash to execute. In fact, the bash totally ignores them.
  • These notes are called comments.
  • It is nothing but explanatory text about script.
  • It makes source code easier to understand.
  • These notes are for humans and other sys admins.
  • It helps other sys admins to understand your code, logic and it helps them to modify the script you wrote.

Multiple Line Comment

You can use HERE DOCUMENT feature as follows to create multiple line comment:

#!/bin/bash
echo "Adding new users to LDAP Server..."
<<COMMENT1
    Master LDAP server : dir1.nixcraft.net.in 
    Add user to master and it will get sync to backup server too
    Profile and active directory hooks are below
COMMENT1
echo "Searching for user..."

External links

← ShebangHomeSetting up permissions on a script →