Hacker News new | ask | show | jobs
by e12e 2167 days 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
  }
1 comments

I 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.
True 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.