[Linux-Biella] aiuto con getopt..

Jumping Jack jumpingjack a jumpingjack.org
Lun 11 Giu 2018 18:11:17 CEST


On 11/06/2018 17:48, Leonardo Buffa wrote:
>
> ciao
>
> non capisco:
>
> codice:
>
> #!/bin/bash
>
> PARSED_OPTIONS=$(getopt -n "$0" -o hdti: --long "help,debug,ip,type:" 
> -- "$@")
>
> if [ $? -ne 0 ];
> then
>   exit 1
> fi
>
> eval set -- "$PARSED_OPTIONS"
>
> while true;
> do
>   case "$1" in
>
>     -h|--help)
>       HELP=true
>       echo "usage $0 -h -d  -i <IP> -t <type> or $0 --help --debug 
> --ip <IP> --type <type>"
>       exit 0
>      shift;;
>
>     -d|--debug)
>       DEBUG=true
>       shift;;
>
>     -t|--type)
>       if [ -n "$2" ];
>       then
>         TYPE=$2
>       fi
>       shift 2;;
>
>     -i|--ip)
>       if [ -n "$2" ];
>       then
>         IP=$2
>       fi
>       shift 2;;
>
>     --)
>       shift
>       break;;
>   esac
> done
>
> echo "Debug: $DEBUG"
> echo "IP: $IP"
> echo "Type: $TYPE"
>
>
>
> non capisco come mai..
> se io do comando:
>
> leos a X1:~$ ./parsa3.sh -d   --type aaaa -i 123
>
> funziona ed ottengo:
>
> Debug: true
> IP: 123
> Type: aaaa
>
>
> leos a X1:~$ ./parsa3.sh -d   --t aaaa -i 123
> NON DOVREBBE perche' il comando --t non esiste pero' funziona e mi da:
>
> Debug: true
> IP: 123
> Type: aaaa
>
>
> ma se do comando:
> leos a X1:~$ ./parsa3.sh -d   -t aaaa -i 123
>
> non fa nulla e se ne sta li...
>
> qualcuno sa peche'?

Io non so perché ma so che se c'è una sola opzione --abcd --a --ab --abc 
funzionano, da qui ho dedotto che le opzioni lunghe posso essere 
accorciate. Se c'è l'opzione --aqwe invece --a dice che è ambiguo, 
mentre --aq o --ab funzionano



Maggiori informazioni sulla lista Linux