0

I have found this in an old script but can't tell what is the use of the "x" infront of the ${VARIABLE} and infront of the value "onx" being compared

VARIABLE="${VARIABLE:-"on"}"
if [ "${VARIABLE}x" != "onx" ]

Are there any effects if the x is removed?

Technas
  • 1
  • 1
  • 1
    It's not needed with proper quoting (which you have) and a vaguely modern shell (which you probably also have), so go ahead and remove it. See [this stackoverflow question](https://stackoverflow.com/questions/174119/why-do-shell-script-comparisons-often-use-xvar-xyes). – Gordon Davisson Feb 16 '21 at 07:51
  • In any modern shell, or at least in `bash`, there will be no difference to the outcome of the test if `x` is removed. See the dupe questions. – Kusalananda Feb 16 '21 at 07:51
  • It's also not needed because of the preceding line that sets `VARIABLE` to a value if it's either unset or empty. Since now `VARIABLE` cannot be empty the `x` guard isn't required – roaima Feb 16 '21 at 08:40

0 Answers0