Skip to content

Instantly share code, notes, and snippets.

@OBdA
Created May 25, 2012 14:29
Show Gist options
  • Save OBdA/2788435 to your computer and use it in GitHub Desktop.
Save OBdA/2788435 to your computer and use it in GitHub Desktop.
Inline manual in shell scripts
#! /bin/sh
__check_for_help()
{
set +u # disable 'nounset' because positional parameters may be unset
# check $0 against the file name because of scripts sourcing shell libraries
# with inline documentation
test $(basename $0) = 'libUMI.sh' -a \( '--help' = "$1" -o '-h' = "$1" \) \
&& exec sed -n '/^#--/ {s/^#--//; p}' $0 | less -+S -FRX && exit 1
}
__check_for_help "$@"
#--
#--NAME
#-- blurb
#--
#--SYNOPSIS
#-- ./blurb --help
#-- ./blurb -h
#--
#EOF
@OBdA
Copy link
Author

OBdA commented Aug 20, 2012

This Gist demonstrates how to include documentation into shell scripts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment