Scripts that take String options

I need help to know how to create a script that takes string options and not only 1 charecter.

I wanted to make a script that takes 'string' options eg. hscript.sh -product XXX -version XXX
I know that I can make a script that takes "1 Charecter " options eg. hscript.sh -m XXX -l XXX -s XXX , with a function called "getopts".

When i tried to use "getopts" to make the options as a string and not only 1charecter the script didn't work.

Try using a while loop to process the parameters, e.g...

while [[ $# -gt 0 ]]
do
    case $1 in
        -product) export PRODUCT=$2 ; shift ;;
        -version) export VERSION=$2 ; shift ;;
               *) echo invalid option ; exit 1 ;;
    esac
    shift
done

Note that options with arguments require additional shifts.

Hi.

I think Ygor's suggestion is relatively easy to implement and useful to know about.

However, there are those extra actions with which getopts-like facilities can help us -- error messages, shifting, etc.

There is a shell version of getopt that can process long options. See Bash long options and Python s-expression parser for details ... cheers, drl