When I try to run the script as below:
./myscript.sh --certtype ca --password xyz --commonname xyz
I get the following error:
+ local BIN_PATH CertType Password Commonname
+ BIN_PATH=keytool
++ getopt -u -o t:p:c -l certtype:password:commonname -- --certtype ca --password xyz --commonname xyz
getopt: unrecognized option '--password'
getopt: unrecognized option '--commonname'
+ options=' --certtype:password:commonname -- ca xyz xyz'
+ echo 'Error on parsing parameters'
Error on parsing parameters
+ exit 1
Below is the script I am trying to execute:
#!/bin/bash
main()
{
set -x
local BIN_PATH CertType Password Commonname
BIN_PATH="keytool"
if ! options=$(getopt -u -o t:p:c:: -l certtype:password:commonname:: -- "$@")
then
# something went wrong, getopt will put out an error message for us
echo "Error on parsing parameters"
exit 1
fi
set -- $options
while [ $# -gt 0 ]
do
case "$1" in
-t | --certtype) CertType="$2" ; shift;;
-p | --password) Password="$2" ; shift;;
-c | --commonname) Commonname="$2" ;shift;;
-- ) shift; break;;
-* ) echo "$0: error - unrecognized option $1" 1>&2; exit 1;;
* ) break;;
esac
shift
done
echo "Cert type is: $CertType"
echo "Password is: $KeystorePassword"
echo "common name is: $CommonName"
}
main "$@"
Am I missing anything in the code above?
Thanks, Firas