I was looking at the source code of NodeSource's installer script for Node.js.
Everywhere in the code, when they want to compare two strings, they prepend X
to both sides before comparing:
if [[ "X${NODENAME}" == "XNode.js 10.x" ]]; then
I was pointed to some questions on the network:
- What's the purpose of adding a prefix on both sides of a shell variable comparison to a string literal?
- Why do shell script comparisons often use x$VAR = xyes?
- Why append an extra character in `test`/`[` string comparison in POSIX sh?
They all explain why this is necessary when comparing with [
. But in this case, the comparison is with [[
.
Is this technique really necessary for [[
?