piotrek piotrek - 9 months ago 78
Bash Question

Quoted colon as a shell comment?

In bash you can type:

ls `: whatever`

and simply current dir will be listed. i saw this syntax used in shell scripts as a comment in multiline commands. but how does it work? is it some kind of shell standard or is bash specific?


It's just a command substitution that produces an empty expansion. It gets abused as a comment because it usually has no effect on the program, but that isn't guaranteed. Consider

 ls `: Don't use a $() here`

It also still requires a subshell to be created in order to run the command, so it slows your script down (however little that may be, but lots of them can add up).

Don't use this: use a proper # comment.