I am trying to play around with getopt options. I want both short options and long options.
For my following test script, it does not produce my required output.
#!/bin/bash
options=$(getopt -o d:f:t: -l domain -l from -l to -- "$@")
[ $? -eq 0 ] || {
echo "Incorrect options provided"
exit 1
}
eval set -- "$options"
while true; do
case "$1" in
-d | --domain)
DOMAIN=$2;
shift 2
;;
-f | --from)
FROM=$2;
shift 2
;;
-t | --to)
TO=$2;
shift 2
;;
--)
shift
break
;;
esac
shift
done
echo "Domain is $DOMAIN"
echo "From address is $FROM"
echo "To address is $TO"
exit 0;
When I try to run it, nothing happens, it just hangs:
# bash getopt_check.sh -d hello.com -f from@test.com -t to@test.com
Expecting output:
Domain is hello.com
From address is from@test.com
To address is to@test.com