3 ms·
i usually do this when I want to create docstring-like behavior cat <<-DOC line 1 line 2 line 3 DOC
by nunez 5y ago
i usually do this when I want to create docstring-like behavior
cat <<-DOC
line 1
line 2
line 3
DOC
- teddyh 5y agoI 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.