In a script i have a list of options that needs to be entered by the user.They are-c cell name -> it must be there-n node -> it must be there-s server -> it must be thereUptill here its all fine my code until here looks like while getopts c:n:s:The problem starts from here,I have two other fields that needs to be entered in an and/or conditon. -i initial heap size-m max heap sizeThe user inputs either both these options or either one.Currently i have something like#get the arguments -c for cell, -n for node, -s for server, -i for initial heap, -m for max heapwhile getopts c:n:s:im opt; do        case $opt in          c)                CELL=$OPTARG                ;;          n)                NODE=$OPTARG                ;;          s)                SERV=$OPTARG                ;;          i)                INI_HEAP=$OPTARG                ;;          m)                MAX_HEAP=$OPTARG                ;;          ?)                echo a.sh -c <CELL> -n <NODE> -s <SERVER> [-i <INITAIL HEAP> | -m <MAX HEAP>                ;;        esacdone#test if cell name is not nullif ! test $CELL || ! test $NODE || ! test $SERV ; then        echo a.sh -c <CELL> -n <NODE> -s <SERVER> [-i <INITAIL HEAP> | -m <MAX HEAP>]        exit 1fi#test if both initial heap and max heap are nullflag=0if ! test $INI_HEAP ; then        if ! test $MAX_HEAP ; then                flag=1;        fifiif [[ $flag -eq 1 ]] ; then        echo flag a.sh -c <CELL> -n <NODE> -s <SERVER> [-i <INITAIL HEAP> | -m <MAX HEAP>]        exit 1fi#test for non numeric value of initial heap sizeif [[ $INI_HEAP == +([0-9]) ]] ; then        continueelse        echo num a.sh -c <CELL> -n <NODE> -s <SERVER> [-i <INITAIL HEAP> | -m <MAX HEAP>]        exit 1fiHow can i get to implement the and/or feature of -i and -m option.
Alternate option field
bash;getopts
Your $flag variable is redundant - you set it, then immediately test for it. You could just echo instead of setting it originally. So the logic is:capture opts/optargsmake sure that CELL, NODE and SERVER are all setmake sure that either INI_HEAP or MAX_HEAP is set, and is an int#get the arguments -c for cell, -n for node, -s for server, -i for initial heap, -m for max heapwhile getopts c:n:s:i:m: opt; do        case $opt in          c)                CELL=$OPTARG                ;;          n)                NODE=$OPTARG                ;;          s)                SERV=$OPTARG                ;;          i)                INI_HEAP=$OPTARG                ;;          m)                MAX_HEAP=$OPTARG                ;;          ?)                echo Usage: a.sh -c <CELL> -n <NODE> -s <SERVER> [-i <INITIAL HEAP> | -m <MAX HEAP>]                exit 1                ;;        esacdone#test if cell name is not nullif [[ -z $CELL || -z $NODE || -z $SERV ]]; then    echo Cell, Node and Server are mandatory values    echo Usage: a.sh -c <CELL> -n <NODE> -s <SERVER> [-i <INITIAL HEAP> | -m <MAX HEAP>]    exit 1fi#make sure either -i or -m was used (or both) and is an integershopt -s extglobif [[ ( -z $INI_HEAP && -z $MAX_HEAP ) || -n ${INI_HEAP##+([0-9])} || -n ${MAX_HEAP##+([0-9])} ]]; then    echo Initial heap size or maximum heap size (or both) must be specified, and must be an integer    exit 1fishopt -u extglob