Bash Standard Command Line Option Processing Pattern: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
(Created page with "=Internal= * bash =Overview= <syntaxhighlight lang='bash'> while -n $1 ; do if done </syntaxhighlight>")
 
Line 7: Line 7:
<syntaxhighlight lang='bash'>
<syntaxhighlight lang='bash'>
while [[ -n $1 ]]; do
while [[ -n $1 ]]; do
   if  
   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
done
</syntaxhighlight>
</syntaxhighlight>

Revision as of 05:57, 20 March 2019

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