Strictly speaking, expression wise, if [ x$feature_platform_search_hint = xy ]
has nothing to do with grub
, it's a shell expression, to be interpreted by shell. grub
is using it in one of it's helper script, that's it.
if [ x$feature_platform_search_hint = xy ]
is basically testing if the variable feature_platform_search_hint
is expanded to y
.
How?
The [
is a synonym for command test
(can be a shell builtin or an external command), used for evaluating expressions.
In if [ x$feature_platform_search_hint = xy ]
:
[
is testing whether strings x$feature_platform_search_hint
and xy
are same
here x
is a placeholder, dummy string, exists on both sides
the variable $feature_platform_search_hint
is expanded first, the value is added to already existing string x
, and then the string on left is compared to the string on the right of =
In effect, it is necessarily checking if variable feature_platform_search_hint
has value y
Here x
is used so that if the variable feature_platform_search_hint
is unset or null, then the [
will exit with an error as =
requires argument on both side, and without feature_platform_search_hint
, this will become:
if [ = y ]
using x
gets us syntactically correct usage in that case:
if [ x = xy ]
Note that, one should instead use the -z
test (which tests if the string is of zero length), or -n
test (non-zero length test), whichever suits best:
if [ -n "$feature_platform_search_hint" ]
if [ -z "$feature_platform_search_hint" ]
One should also quote variables (although strictly not necessary in this case as presumably the author intended to define/overwrite the variable inside the script only):
if [ x"$feature_platform_search_hint" = xy ]
bash
. It isGRUB
thought it may look completely like abash
.