Comments
Comments should be indented to the same level as the code they are commenting if they appear above a block of code. Inline comments can be added to a single line if they do not push the line beyond 79 characters. Single-line comments should not end with a period. All comments should capitalize the first word unless that would break a reference to a case-sensitive object such as a variable, utility, manual, et cetera.
1
#
2
# Comment above a block consisting of 4 or more lines
3
#
4
if some condition; then
5
line1
6
line2
7
fi
8
9
# Comment above a block consisting of 3 lines of less
10
if some condition; then
11
line
12
fi
13
14
some condition && foo=bar # Comment
Copied!
Multiline comments should end with a period.
1
#
2
# Multi-line comment above a block consisting of 4 or more lines. Lines break
3
# at column-80 (which should never contain any character).
4
#
5
if some condition; then
6
line1
7
line2
8
fi
9
10
# Multi-line comment above a block consisting of 3 lines or less. Lines break
11
# at column-80 (which should never contain any character).
12
if some condition; then
13
line
14
fi
15
16
some condition && foo=bar # Multi-line comment for a single line. Line breaks
17
# at column-80 (which should never contain any character).
Copied!
When commenting lines of code to disable their execution, use #? instead of the traditionally used #.
1
#
2
# Comment above a block of 4+ lines of commented-out code
3
#
4
#?if some condition; then
5
#? line1
6
#? line2
7
#?fi
8
9
# Comment above a block of 1-3 lines of commented-out code
10
#?if some condition; then
11
#? line
12
#?fi
13
14
#?some condition && foo=bar # Comment after commented-out line
Copied!
If it is not obvious from reading a line that execution is prematurely terminated, add # NOTREACHED as a comment.
1
case "$flag" in
2
...
3
*) usage # NOTREACHED
4
esac
5
6
some condition && myfunc # NOTREACHED
Copied!
If a result is ignored, add a comment to the effect.
1
printf "< Press ENTER to continue >"
2
read ans # Ignored
Copied!
Copy link