Monday, March 13, 2017

Bash Scripting: simple demonstration of the getopts command

#!/bin/bash
#
#    simple demonstration of the getopts command
#
echo
while getopts :ab:c opt
do
        case "$opt" in
                a) echo "Found the -a option" ;;
                b) echo "Found the -b option, with value $OPTARG" ;;
                c) echo "Found the -c option" ;;
                *) echo "Unknown option: $opt" ;;
        esac
done
#




User enters:


./test19.sh -acb testb




Results:

Found the -a option
Found the -c option
Found the -b option, with value testb

No comments:

Post a Comment