I need help figuring out one issue in my script, options ( c, e , d, f and g) are mandatory options in my script and they are always implied before running my script otherwise script wont be executed. Now i have added a command and if i tried to to execute my script without any necessary parameters, it’d be still be executed and exit out , my script shouldn’t be executing without passing any required parameters but it still does and exits out. how can i fix this?
Thank you in advance,
#!/bin/bash
cont=false
options=':c:d:e:f:g:h:i' # additional option characters go here
while getopts $options option
do
case $option in
c ) cont=true;;
d ) hello="$OPTARG"
e ) hi="$OPTARG"
f ) Fri="$OPTARG"
g ) Sat="$OPTARG"
h ) SUN="$OPTARG"
i ) ....so on
# more option processing can go here
esac
done
shift $(($OPTIND - 1))
Using an array called
mandatorythat contains required options and setting the array element to-for given options, the code below reports an error for unspecified mandatory options: