points by teddyh 4 years ago

I once created a set of shell functions which I wanted to have a docstring-like functionality. The solution I came up with was to have each shell function start with the : command with a string as an argument. Since : is an actual command, not a comment, it was preserved as part of the function, and could be extracted at runtime using relatively simple parsing to do introspection.

Example:

  foo(){
    : "This is a docstring for the foo() function"
    bar --verbose | baz --quiet
  }

For those who don’t know: ":" is a shell built-in command which does nothing and ignores all arguments. It was the way in which shell scripts had comments before the modern syntax of using # for comments was introduced.

nunez 4 years ago

That's insane. MSDOS Batch used the same syntax for comments!

  • teddyh 4 years ago

    No, I’m pretty sure MS-DOS used "rem" (for “remark”) to do comments.

    Colons, “:”, in batch files were, IIRC, for labels, i.e. targets for “goto” statements.