[Linux-Biella] aiuto con getopt..

Leonardo Buffa leonardo.buffa a bilug.it
Lun 11 Giu 2018 17:48:13 CEST


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'?


Maggiori informazioni sulla lista Linux