Created
August 22, 2019 08:57
-
-
Save emres/232db2984a0ac1ab8116fcdfaa45d19f to your computer and use it in GitHub Desktop.
Bash block and multiline comment styles
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
: <<'### README ###' | |
Style 1 | |
======= | |
This is a multiline comment, created by combining two relatively | |
less known Bash features, the `:` command, and Here Documents. | |
This has the advantage of less syntactic noise per line, and the | |
ability for syntax highlighting in case you have embedded code | |
block in comments (this can be a double-edged sword, though, | |
because highlighting regular English words that are also Bash | |
keywords such as for, in, fi, etc. | |
Moreover, this uses a relatively obscure features of Bash, and | |
violates the Principle of Least Astonishment. | |
Example usage: | |
$ bash bash_multiline_comment.sh | |
### README ### | |
################################################################ | |
# | |
# Style 2 | |
# ======= | |
# Or you can go with the traditional style, which is, of course | |
# not the block comment style as above, but rather a multiline | |
# comment, by commenting out each line. | |
# | |
# This style uses only one feature of Bash, and is less obscure. | |
# A minor disadvantage is losing syntax highlighting for code | |
# blocks embedded inside this style of comment: | |
# | |
# Example usage: | |
# | |
# $ bash bash_multiline_comment.sh | |
################################################################ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment