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 x
on 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:
if [ x$USER != x$RUN_AS_USER ]
There if you just had $USER
and it were empty then you could end up with
if [ != root ] # Syntax error
With the x
you get this, which is better:
if [ x != xroot ]
However, when the variables are quoted the x
is unnecessary since an empty string in quotes isn't removed entirely. It still shows up as a token. Thus
if [ "$USER" != "$RUN_AS_USER" ] # Best
is the best way to write this. In the worst case with both variables empty you'd get this which is a valid statement:
if [ "" != "" ]