0

Here is the skeleton to catch arguments in my script :

# fMain(){

        while getopts "d:e:h" _OPTION; do
                case $_OPTION in
                d)                              
                        dateVal=$OPTARG
                        ;;
                e)
                        extensionVal=$OPTARG
                        fListArgument "OPN_BYPASS" $OPTARG
                        ;;
                h)
                        fToonHelp
                        ;;
                \?)     echo "Please run '$0 -h' for help"
                        vARG_VLAG="Y"
                        ;;
                esac
        done

        exit 0

How can I set the options d and e mandatory ? I could simply throw an error if they are not filled (using a binary variable to see if they are filled or not). But I guess, a more convenient way to do this exists.

0
if [ -z "$dateVal" ]; then
           printf "Option -d must be specified\n"
           exit
fi
if [ -z "$extensionVal" ]; then
           printf "Option -e must be specified\n"
           exit
fi
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.