I’m peeking through some shell scripts – what’s the purpose of the x in the comarison shcu as
if [ "x$USER" != "x$RUN_AS_USER" ]; then
su - $RUN_AS_USER -c "$CATALINA_HOME/bin/startup.sh"
else
$CATALINA_HOME/bin/startup.sh
fi
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It’s a trick to ensure you don’t get an empty string in the substitution if one of the variables is empty. By putting
xon both sides it’s the same as just comparing the variables directly but the two sides will always be non-empty.It’s an old kludge which made more sense when scripts were written as:
There if you just had
$USERand it were empty then you could end up withWith the
xyou get this, which is better:However, when the variables are quoted the
xis unnecessary since an empty string in quotes isn’t removed entirely. It still shows up as a token. Thusis the best way to write this. In the worst case with both variables empty you’d get this which is a valid statement: