My current Bash script looks like in the following. So far it's working except the option -g
. I'd like this option to be optional but it cannot be used without any of -c
or -n
.
So what I mean is:
-g
shall be completely optional- If, however, it is given then
-c
or-n
must also be present.
Unfortunately I don't have any idea how to do that.
while getopts ':cniahg:' opt; do
case $opt in
g) DAYS_GRACE_PERIOD=$OPTARG ;;
c) prune_containers ;;
i) prune_images ;;
n) prune_networks ;;
a)
prune_containers
prune_networks
prune_images
;;
:) echo "Invalid option: $OPTARG requires an argument" 1>&2 ;;
h) print_usage ;;
\?) print_usage ;;
*) print_usage ;;
esac
done
shift $((OPTIND - 1))