I wonder if it's possible to reduce the last four lines in the following example:
#!/bin/bash
function xxx {
echo $#
echo $1
}
[[ -n $SOME_ENV ]] && P="-Dabc=$SOME_ENV"
if [[ -n $P ]]; then
xxx "$P" abc
else
xxx abc
fi
Replacing the if-else-fi by just
xxx "$P" abc
does work if $P is not empty, otherwise not because "" still counts as empty parameter. Omitting the quotes around $P does not work if SOME_ENV contains spaces. I know that it's possible with "eval", but eval is evil: http://mywiki.wooledge.org/BashFAQ/048
Any other solution?