&&
is a logical "and"; essentially, it lets you do something based on whether the previous command completed successfully (although this might not be true in more complex cases, for example, consider true || false && echo true
, here's an article on on boolean logic rules). Another way of writing the statement in your question would be:
if test ".$TOMCAT_USER" = .; then
TOMCAT_USER=tomcat
fi
This is a strange way of testing for an unset/null variable, though. POSIX already has multiple ways to do that:
: "${TOMCAT_USER:=tomcat}" # Assign as part of the expansion,
# `:' is a noop to avoid running the expansion.
TOMCAT_USER="${TOMCAT_USER:-tomcat}" # Expand, and then assign
The difference between the :=
/:-
and :
-less versions are that the :
versions also test if the variable is null in addition to testing if it is unset (which is closer to your original test).
&&
it's Boolean, means if first statement is successfully run (means exit status code is zero ) then run another statement. you can run script in debug mode to understand likebash -x scriptname