Petite fonction rapide pour parser les paramètres d'un script en sh, pratique si on a un petit script à faire avec plusieurs paramètres et qu'on veut pas s'emmerder avec l'ordre des arguments
## exemple.sh # # Mandatory arguments to long options are mandatory for short options too. # -v, --verbose set verbose mode on # -a, --arg VALUE specify a value for a var # -h, --help display this help and exit # read_parameters gets all command-line arguments and analyzes them # read_parameters() { # for all parameter give to the script while [ "$1" != "" ] ; do case "$1" in -h|--help) usage; exit ;; # run usage function -v|--verbose) VERBOSE="ON" ;; # set VERBOSE var -a|--arg) shift; VALUE="$1";; # get the value of the arg *) printf "error : invalide option -- $1\n" printf "error : Try $0 --help' for more information.\n" exit ;; esac # in case of no argument give to an option # shift execute an exit if already empty # add test to avoid this at least to print error message [ "$1" != "" ] && shift done main_function(); }