Today I saw a bash script use a colon to denote a comment. What's the difference between using a colon and a hash mark?
: This is a comment.
# This is also a comment.
For one, I know you can't use a colon for a trailing comment:
cd somedir : This won't work as a comment.
But the fact that the above example works has me puzzled about how :
is evaluated.
General Usage Rules In America, Canada, Australia and New Zealand, the general rule is that double quotes are used to denote direct speech. Single quotes are used to enclose a quote within a quote, a quote within a headline, or a title within a quote.
Double quotation marks (in British English) are used to indicate direct speech within direct speech (use single inverted commas for direct speech and double quotation marks to enclose quoted material within).
They are two entirely different punctuation symbols. Single quotes are limited to one real function in written U.S. English, which is to indicate a quotation within a quotation. Apostrophes, on the other hand, are used to denote possessive form and to indicate omission.
Inverted commas are mainly used to introduce quotations or direct speech. This is why the name quotation mark is used as a synonym for inverted commas. A direct quote (the exact words spoken or written) must be always written inside quotation marks.
:
is simply an alias for true
, and true
ignores its arguments:
# Does nothing:
true foo bar etc hello
# Does the same:
: foo bar etc hello
It's not a comment and should never be used as a comment, because all its arguments are still parsed and evaluated:
: This "comment" actually executes this command: $(touch foo)
ls -l foo
or like here, where StackOverflow's syntax highlighting picks up that the command in the middle is actually just text, even if a human doesn't:
: The command below won't run:
echo "Hello World"
: because the surrounding "comments" each contain a ' characters
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With