Code Fragment Collection
Web
asperix.org
Home
Contact
Categories
BASH
Shell
PHP
APL
SQL
C++
All
Documentation
License
Related
C++ Articles
APL Library
Math Library
Geo Library
mirzoyan.com
C++ Articles
Humor
Parsing command line
show_help= show_version= option= param= while test $# -gt 0 ; do arg=`expr "x$1" : 'x[^=]*=\(.*\)'` case $1 in --help | -h | '-?' ) show_help=yes ;; --version | -v ) show_version=yes ;; --opt | --option | -o ) option=yes ;; --param | --param=* ) test -z "$arg" && shift && test $# -gt 0 && arg=$1 param=$arg ;; -*) echo invalid option: $1 && exit 1 ;; *) # process argument echo "argument: [$1]" ;; esac shift done echo "show_help [$show_help]" echo "show_version [$show_version]" echo "option [$option]" echo "param [$param]"
Copyright (C) 2006 Andrey Mirzoyan