I'm not a good Shell Script expert. Can somebody help me to understand and explain the statement [ ! -z ${TRUE:-} ] && [ ${TRUE:-} == 'true' ] &&
from the following snippet. What is this specific statement doing and/or being validated for?
However, am able to understand this statement: TRUE=$($JBOSS_TWIDDLE get jboss.system:type=Server Started |grep Started |cut -d"=" -f2)
. This basically calling a JBoss's JMX command-line tool to check the server start status.
Code Snippet:
while [ $i -lt 180 ]; do
TRUE=$($JBOSS_TWIDDLE get jboss.system:type=Server Started |grep Started |cut -d"=" -f2)
[ ! -z ${TRUE:-} ] && [ ${TRUE:-} == 'true' ] && {
echo "The $JBOSS_NAME server is up and running."
return
}
The elaborate precautions against $TRUE being empty are not needed if double quotes are used.
The -z tests if $TRUE is not empty, and :- substitutes nothing if it is unset. It is all unnecessary. Perhaps it is a protest against an over-prescriptive coding standard.
As @drew-khoury and @ramruma point out, the
[ -z ...
test is superfluous.Using
TRUE
as the name of a variable just adds to the confusion.The actual question that snippet tries to answer is: did
twiddle.sh
printStarted=true
? Or, in shell speak:The
grep ... | read
construct will return true if grep was successful, while dropping the output.