Pattern: Use of x-prefix in comparison
Issue: -
Some older shells would get confused if the first argument started with a dash, or consisted of !
or (
. As a workaround, people would prefix variables and values to be compared with x
to ensure the left-hand side always started with an alphanumeric character.
POSIX ensures this is not necessary, and all modern shells now follow suite.
Example of incorrect code:
[ "x$pass" = "xswordfish" ]
test x"$var" = x
Example of correct code:
[ "$pass" = "swordfish" ]
test "$var" = ""