Bash Standard Command Line Option Processing Pattern

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

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