Param Pattern

A generalization of previous patterns and tips.

Motivation:

Every script must have certain functionality like a help option or an edit option. How incorporate those functionalities without add complexity and extra work to the script?

Solution:

Create a script that hold the functionality needed to add extra options to new scripts. Then, in every new script call that script for added functionalities.

Create a file named paramPattern.sh containing:

  scriptPath=`type $1 | awk '{ print $3 }' `
  case $2 in
  -edit)
${EDITOR:-vi} $scriptPath
exit 1
;;
  -help)
sed -n '/^##/s/^## //p' $scriptPath
exit 2
;;
  esac
  exit 0
In existing or new scripts insert:
  paramPattern $0 $1 ||
exit 1
  ...
-- GabrielGasparolo (mailto:ggasp@hotmail.com)


See also: OptionParsingInShell


CategoryUnixShellPattern


EditText of this page (last edited October 3, 2003) or FindPage with title or text search