getopt help

:slight_smile:
Can anybody help me about how to use getopt in shell scripting.

Have you checked the internet search engines for it yet? There are plenty of examples which could not be explained much easier.

checked, but not fully explained and every page has different syntax and usage, so confused little bit.

while getopts "abc:d" option
do
        case $option in
                a)   echo "Option a" ;;
                b)   echo "Option b" ;;
                c)   echo "Option c with argument $OPTARG" ;;
                d)   echo "Option d" ;;
                \?)  echo "Wrong argument, usage is ...." ;;
                *)   echo "Not expected input, try again!" ;;
        esac
done

Possbile parameters are a, b, c and d. Since there is a colon following to "c", it awaits an argument, for example a name, a filename, whatever, and will store it in $OPTARG.