Xymon Mailing List Archive search

Configuring Devmon for the first time

list Buchan Milne
Thu, 2 Jun 2011 10:10:27 +0200
Message-Id: <user-f486ff868d25@xymon.invalid>

On Thursday, 2 June 2011 09:37:01 John P Martin wrote:
I agree it's a bit off-topic, but just to answer the question:

The "x" prefix for testing variables (more commonly the upper case "X",
because that's the example in the man page :-)
Out of curiosity, which man page?
is common practice to avoid
the test getting confused by unexpected values in the variable,
in crappy shells (typically found on crufty old proprietary Unix).
In
particular, the test tends to throw the comparison out if the variable
should start with a "-".  Prefixing the variable would convert this to
"X-", which is correctly processed by the test comparison.

For example:

VAR="-value"

[ "$VAR" == "something" ] will fail, trying to process "-value" as a
qualifier.

[ "X$VAR" == "Xsomething" ] will correctly find an inequality
$ foo=purple;if [ "$foo" == "purple" ];then echo yes;else echo no;fi
yes
$ foo="-blue";if [ "$foo" == "purple" ];then echo yes;else echo no;fi
no
$ foo="red";if [ "$foo" == "purple" ];then echo yes;else echo no;fi
no
$ echo $SHELL
/bin/bash

Regards,
Buchan