wwerner / bashplate

Bashplate generates bash script boilerplate code for option parsing and validation
https://bashplate.wolfgang-werner.net
MIT License
16 stars 1 forks source link

Consider merging GNU and POSIX templates and use getopt/getopts based on availability #4

Open wwerner opened 5 years ago

wwerner commented 5 years ago

Using this pattern, we can detect whether GNU getopt is available and use it:

getopt -T > /dev/null
if [ $? -eq 4 ]; then
    # GNU enhanced getopt is available
    set -- `getopt --long help,output:,version --options ho:v -- "$@"`
else
    # Original getopt is available
    set -- `getopt ho:v "$@"`
fi
wwerner commented 5 years ago

As an alternative, we could use the getops.sh script providing a posix compliant parser for long options: https://gist.github.com/wwerner/31758b8083746eb285e7eb62b55e532e