Bash: gérer les options d’un script

Written by admin on July 9, 2012 Categories: Ligne de commande, Linux Tags: , ,

Je veux passer des options à un script

#!/bin/bash

eval set -- $(getopt -n $0 -o "-sh"  -l "longoption" -- "$@")
if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi
while [ $# -gt 0 ] ; do
        case "$1" in
                -h) TODO; shift;;
                -s) TODO; shift;;
                --longoption) TODO; shift;;
                --) shift;;
                -*) echo "Mauvaise option '$1'"; exit 1;;
                *) shift;;
        esac
done

# Continue parsing normal argument with arg or $@

Source:

http://stackoverflow.com/questions/402377/using-getopts-in-bash-shell-script-to-get-long-and-short-command-line-options

http://stackoverflow.com/questions/16483119/example-of-how-to-use-getopts-in-bash

No Comments on Bash: gérer les options d’un script

Leave a Reply

Your email address will not be published. Required fields are marked *