26 March 2013
The colon as a placeholder
When writing a script, I like it always to be a valid script, one
that can run without any syntax errors.
When I write the outline of a for
or while
loop, I want it to be an executable piece of code even before I have
written the code that will go inside it.
The basic loop will not do:
while read line do done
It will give me an error:
bash: syntax error near unexpected token `done'
Since such constructs are programmed as macros or functions in my editor, I modified them to create executable code by adding a colon:
while read line do : done
The function macro also puts in comments where I will add at least minimal documentation for the function:
function_name() #@ { : #@ USAGE: function_name }
It's a small thing, but a useful one.
Modified 18 Nov 2021