cleaning out optional arguments and passing it out shell script

I am trying to execute a cpp binary from shell script.. The cpp takes arguments and some of them are optional.

So basically what I am trying to do is generating the appropiate string and then executing that string something like:

    generated_string="$string $param1 --param2=$param2"
    echo $generated_string

#  execution function
    read -p 'param1: ' param2
    read -p 'param2: ' param2
    echo 'optional arguments'
    *read -p "param3: " param3   
    read  -p "param4: " param4*
    string=$(generate_string $param1 $param2 ???????)
    eval $string

Now in this function.. either or both of param3 and param4 can be blank What I want is if it is blank then offcourse I dont generate it in a string.

But I feel its too messy to have if statements..

Is there a way to solve this gracefully


This should work sir


usage ()
  echo usage: $0 PARAM1 PARAM2 [PARAM3] [PARAM4]

[ $2 ] || usage
eval "path/to/binary" "$@"


 ? How to denote that a command line argument is optional when printing usage
 ? Shell script with options and argument - Update
 ? Running C Executable With Arguments As C Executable From Shell Script
 ? UNIX Shell scripting/Menu
 ? Find and replace: \'
 ? Find and replace: \'
 ? Find and replace: \'
 ? replace with sed on Mac OS X Leopard doesn't do what expected
 ? Change find and replace every iteration
 ? Using sed to replace text with spaces with a defined variable with slashs