checkopt

Package: WA2L/edrc 1.5.57
Section: Library Commands (3)
Updated: 08 April 2009
Index Return to Main Contents

 

NAME

checkopt - check used options in shellscripts

 

SYNOPSIS

edrc/lib/checkopt -h

checkopt "used_opts" "truthtable"

checkopt "used_opts" "


header
row_1
row_2
.....
row_n
"

 

AVAILABILITY

WA2L/edrc

 

DESCRIPTION

check if a list of used options matches against a table of allowed option combinations.

This command is intended to be used to efficiently parse arguments in a script.

 

OPTIONS

"used_options"
continuous or space separated string of options that were used. The characters ._:;=+|- are considered as separators and therefore cannot be part of a list of used options.

The order of the options provided in used_options is not significant.

"truthtable"
truth table of the format "header row_1 row_2 row_3 ... row_n " :

header
the header line defines the meaning of the fields defined in the row settings. Only single-character options can be checked by the checkopt command.

The characters ._:;=+|- can be used to format the header content.

row
in the row settings the possible correct option combinations are defined. The following settings are recoginzed as 'option is used': 1, T, True, Y, Yes, the settings 0, F, False, N, No are recognized as 'option not used'.

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.

 

ENVIRONMENT

-

 

EXIT STATUS

0
used option combination is correct.

1
used option combination is not correct.

4
usage printed.

 

FILES

-

 

EXAMPLES

1) example usage in a shellscript

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 $*

2) alternate checkopt usage

alternate use of checkopt. This usage is equal to example 1).

checkopt "$opts" "
        fnv
        YNN
        YNY
        YYN
"

3) alternate checkopt usage

alternate use of checkopt. This usage is equal to example 1).

checkopt "$opts" "
        fnv
        TFF
        TFT
        TTF
"

4) alternate checkopt usage

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
"

 

SEE ALSO

edrcintro(1), getopt(1)

 

NOTES

-

 

BUGS

-

 

AUTHOR

checkopt was developed by Christian Walther. Send suggestions and bug reports to wa2l@users.sourceforge.net . 

 

COPYRIGHT

Copyright © 2009 Christian Walther

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.


 

Index

NAME
SYNOPSIS
AVAILABILITY
DESCRIPTION
OPTIONS
ENVIRONMENT
EXIT STATUS
FILES
EXAMPLES
SEE ALSO
NOTES
BUGS
AUTHOR
COPYRIGHT

This document was created by man2html using the manual pages.
Time: 00:13:56 GMT, March 08, 2025