Shell scripts use the hash (#) symbol for comments:
#!/bin/bash
## This is a comment in a shell script
echo "LabEx Linux Tutorial"
: '
This is a multi-line comment
in bash script
'
Python supports both single and multi-line comments:
## Single-line comment in Python
'''
Multi-line comment
Using triple quotes
Supported in Python files
'''
def example_function():
"""
Docstring comment
Provides function documentation
"""
pass
C and C++ files support multiple comment styles:
// Single-line comment
/*
* Multi-line comment
* Spanning multiple lines
*/
/**
* Documentation comment
* Used for generating API docs
*/
graph TD
A[Comment Placement] --> B[Above Code Block]
A --> C[Inline Comments]
A --> D[End of Code Line]
A --> E[Function/Class Header]
Location |
Recommendation |
File Header |
Describe file purpose, author, date |
Function Header |
Explain function's purpose, parameters |
Complex Logic |
Explain why, not what |
Temporary Code |
Mark with TODO or FIXME |
## TODO: Implement error handling
## FIXME: Resolve performance issue
## NOTE: Requires further investigation
Configuration files in Linux often use specific comment styles:
## This is a comment in configuration files
; Alternative comment style
## LabEx recommends clear, concise comments
Automated Documentation Generation
graph LR
A[Documentation Tools] --> B[Doxygen]
A --> C[Sphinx]
A --> D[JavaDoc]
#!/usr/bin/env python3
"""
Linux File Comments Tutorial
Created by LabEx Developer
Date: Current Year
"""
def calculate_total(items):
"""
Calculate total cost of items
Args:
items (list): List of item prices
Returns:
float: Total cost
"""
## Validate input
if not items:
return 0.0 ## Handle empty list
return sum(items) ## Calculate total
By mastering these comment techniques, developers can create more readable and maintainable Linux files across various programming languages.