Need help with parsing the arguments using getopts !!

Hi all,
I am trying to use long arguments for my existing script. right now my script would work if given <script_name> -t <arg1> -b <arg2> -v <arg3>. The script code is shown below.

while getopts t:v:b: OPT;do
    case "$OPT" in
        t) Todo=$OPTARG;;
        b) Batch=$OPTARG;;
        v) version=$OPTARG;;
        *) Usage;;
    esac
done

Is it possible to achieve the code below using getopts?? I have tried several times and was unsuccessful.

 <script_name> -todo <argument1> -batch <argument2> -version <argument3> 

Here is not getopts answer which I use always.

Todo=""
Batch=""
while [ $# -gt 0 ]
do
         OPT="$1"
         case "$OPT" in
              -t|--todo) Todo="$2" ; shift ;;
              -b|--batch) Batch="$2" ; shift ;;
              --) shift; break ;;  # no more options
              --*|-*) Usage ;;
              *) break ;;  # not option, it's argument
         esac
         shift
done
1 Like

It works great, but i am still wondering if some one could help me out in using the getopts command.

getops does not support long arguments, no.