reduce the or conditions

Hi ,

how can i reduce the or conditions:

if [[ -z $XXXX || -z $YYYYY || -z $TTTT || -z $NNNN || -z $QQQQ ]]; then

whatever

fi

Do you want to speed it up? Consider putting the likeliest cases on the left hand side of the if statement, if this is POSIX shell.

Otherwise, what are you trying to do?

How about?

case "+$XXXX+$YYYYY+$TTTT+$NNNN+$QQQQ+" in
 *++* ) whatever;;
esac

Incorrect post, Moderators please delete this

I am trying to check if all the variables has been initialized or not. there are too many 'or' (||) conditions which i want to reduce so that it looks better

It's not clear what you mean by "looks better". Exactly what would "look better" look like? Assuming your variables do not contain whitespace, another alternative without || might be

if [[ `echo $XXXX $YYYYY $TTTT $NNNN $QQQQ |wc -w` -ne 5 ]]; then
whatever
fi

To exit the script if any var is empty or unset:

: ${XXXX:?} ${YYYYY:?} ${TTTT:?} ${NNNN:?} ${QQQQ:?}

To execute something if any parameter is empty or unset:

var=${XXXX:+A}${YYYYY:+A}${TTTT:+A}${NNNN:+A}${QQQQ:+A}
if [ ${#var} -ne 5 ]; then

THis is exactly what i was looking for. could you explain this please???

First example:

: -- a command that does nothing but evaluate its arguments.

${XXXX:?} -- Bourne-shell parameter expansion; exits with an error if the variable is unset or empty.

${YYYYY:?} ${TTTT:?} ${NNNN:?} ${QQQQ:?} -- Ditto

Second example:

${XXXX:+A} -- Bourne-shell parameter expansion that replaces the variable with [b]A if it is set and not null.

var -- will contain AAAAA (i.e., have a length of 5) if all the variables are set and not null. If any are unset or null, the length of $var will be less than 5.

${#var} -- POSIX parameter expansion that gives the number of characters in the variable.