My script gets a bunch of values for various arguments from a text file and puts them into variables. Then, the following line is run to execute a shell command with the various options:
cmd -a $a -b $b -c $c
;
However, how should I deal with the case where some arguments are not defined? Say -c is optional and thus the user leaves it blank in the text file. Right now if the code runs it would do
$a = "foo";
$b = "bar";
$c = "";
`cmd -a $a -b $b -c $c ` ; # this evaluates to "cmd -a foo -b bar -c"
which gives an error since -c needs an argument. Without implementing if-statements to consider each possible case for variable definition, is there a clean way to deal with this?
Thanks.