checkopt "used_opts" "truthtable"
checkopt "used_opts"
"
This command is intended to be used to efficiently parse arguments in a script.
The order of the options provided in used_options is not significant.
The characters ._:;=+|- can be used to format the header content.
The used_options are checked against each row in the truthtable. If the used options match against a row, the checkopt command exits with exit code 0, if no row matches, the exit code is 1.
The characters ._:;=+|- can be used to format the row content.
Parsing of a command having the usage:
my_script
-h
|
-f file
[
-n
|
-v
]
#!/bin/sh
:
:
parse_args(){ args=$*
debug=False
Patchfile=""
Noexecute=False
Verbose=False
getopt xhf:n $* > /dev/null 2>&1
if [ $? -ne 0 ]; then
usage
fi
opts=""
while [ $# -ge 1 ]; do
opts="$opts $1"
case $1 in
-x) debug=True ;;
-f) Patchfile=`rel2abs $2`
shift ;;
-n) Noexecute=True ;;
-v) Verbose=True ;;
-h|*) usage ;;
esac
shift
done
checkopt "$opts" "
fnv
100
101
110
" || usage
} # parse_args
main(){
parse_args $*
:
:
} # main
main $*
alternate use of checkopt. This usage is equal to example 1).
checkopt "$opts" "
fnv
YNN
YNY
YYN
"
alternate use of checkopt. This usage is equal to example 1).
checkopt "$opts" "
fnv
TFF
TFT
TTF
"
alternate use of checkopt. This usage is equal to example 1).
checkopt "$opts" "
f-----n-----v----
True--False-False
True--False-True
True--True--False
"
This is free software; see edrc/doc/COPYING for copying conditions. There is ABSOLUTELY NO WARRANTY; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.