Bash — Comments
Single-line comments
#!/bin/bash
# This is a comment
echo "Hello" # Inline comment
Multi-line comments
#!/bin/bash
: '
This is a multi-line comment.
It spans multiple lines.
Useful for longer explanations.
'
echo "Hello"
Documenting scripts
#!/bin/bash
# Script: hello.sh
# Author: Your Name
# Date: 2026-08-23
# Description: Prints a greeting message
# Usage: ./hello.sh [name]
echo "Hello, ${1:-World}!"
When to comment
- Explain why something is done
- Document script purpose and usage
- Mark TODOs and FIXMEs
- Don't comment obvious code
Mini Practice
Write Bash code that:
- Uses
#comments to explain variables - Uses
: '...'for multi-line comments - Documents a script with header comments
Up Next
In the next lesson, you'll learn about Variables — declaring and using variables in Bash.
Related Topics
Frequently Asked Questions about Comments
What is Comments in Bash?
Comments is a fundamental concept in Bash. This lesson explains it step by step with clear examples, making it easy for beginners to understand.
How do I learn Comments?
Start by reading the explanation above, then try the code examples. Practice by modifying the examples and experimenting with different values. Hands-on practice is the best way to learn Comments.
Why is Comments important in Bash?
Comments is essential for Bash development. Understanding this concept will help you write better code and solve real-world problems more effectively.