0
0
Bash Scriptingscripting~5 mins

Documentation with comments in Bash Scripting

Choose your learning style9 modes available
Introduction
Comments help explain what your script does. They make it easier to understand and fix later.
When you want to explain what a part of your script does.
When you share your script with others so they understand it.
When you come back to your script after some time and need a reminder.
When you want to temporarily stop a line of code from running.
When you want to add notes about how to use the script.
Syntax
Bash Scripting
# This is a comment in bash
# Anything after # on the same line is ignored by the shell
Comments start with a # symbol and continue to the end of the line.
You cannot put comments inside strings; they must be separate.
Examples
A simple comment before a command to explain what it does.
Bash Scripting
# This script prints Hello World
echo "Hello World"
A comment can be placed after a command on the same line.
Bash Scripting
echo "Start"  # This prints Start
Use comments to leave notes or reminders for yourself.
Bash Scripting
# TODO: Add error handling here
Sample Program
This script uses comments to explain what it does and where it ends.
Bash Scripting
#!/bin/bash

# This script greets the user

echo "Hello!"

# End of script
OutputSuccess
Important Notes
Use comments to make your scripts easier to read and maintain.
Avoid over-commenting; only explain parts that are not obvious.
Comments do not affect how the script runs.
Summary
Comments start with # and explain your code.
Use comments to help yourself and others understand your scripts.
Comments are ignored when the script runs.