4 ms·
It's a little sad that standard shell here documents only support elliding leading tabs (it wouldn't be so sad if the record separator hadn't been thrown under
by e12e 6y ago
It's a little sad that standard shell here documents only support elliding leading tabs (it wouldn't be so sad if the record separator hadn't been thrown under the bus - having a character for indentation distinct from space is good... In theory).
But at any rate my typical usage() is generally along these lines (warning watch out for expansions):
usage()
{
cat - <<-EOF
`basename ${0}`: demonstrate here docs
Usage:
`basename ${0}` <required argument> [-o|--optional-param]
Etc. Possibly referencing
default value: ${DEFAULT_VALUE}
EOF
}
- jolmg 6y agoI think it'd be better without using basename, just $0. That way it matches the way it was called, which is how the user chose to access it for whatever reason. The bare filename might refer to a different command, even. Also, if you include examples in the help text, they'll also be able to copy and paste, instead of having to manually insert what basename stripped away.
- e12e 6y agoTrue enough - I find it depends a bit on the nature of the script - if it's something buried under misc/tools/extra/bin/util.sh - i tend to prefer brevity - especially in the first paragraph/usage section (util.sh <required param> [optional param]). But for more concrete examples I'll often leave off the basename - for easier cut and paste.