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
Using this pattern, we can detect whether GNU getopt is available and use it: