Bash Standard Command Line Option Processing Pattern

From NovaOrdis Knowledge Base
Revision as of 19:27, 13 May 2019 by Ovidiu (talk | contribs) (→‎Internal)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Internal

Overview

while [[ -n $1 ]]; do
  if [[ $1 = "--verbose" ]]; then
    # no value
    ....
  elif [[ ${1:0:7} = "--type=" ]]; then 
    # value expected
    type=${1:7}  
    ...
  else
   echo "unknown argument $1" 1>&2
  fi
  shift
done