<html>
  <head>
    <meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    On 04/26/2013 08:58 AM, Cristian Sava wrote:<br>
    <blockquote cite="mid:1366981090.3007.8.camel@s194.central.ucv.ro"
      type="cite">
      <pre wrap="">Webalizer is enabled via /etc/sysconfig/webalizer but I don't understand
why /etc/cron.daily/00webalizer has this line:

[ "z$WEBALIZER_CRON" != "zyes" ] &amp;&amp; exit 0

that I think it should be (and it is working this way)

[ "$WEBALIZER_CRON" != "yes" ] &amp;&amp; exit 0

What is the mistery?

</pre>
    </blockquote>
    The two versions you quoted are functionally equivalent on Linux. If
    there's a z before the variable expansion and a z  before the word
    "yes", then the two z's cancel out and don't affect the string
    comparison.<br>
    <br>
    As for why they are there, it's an old shell programmers' trick to
    avoid causing syntax errors when doing string comparisons to empty
    strings. Let me explain...<br>
    <br>
    If you do this:<br>
    <br>
    [ $WEBALIZER_CRON != yes ]<br>
    <br>
    and the variable WEBALIZER_CRON is empty, then the command above
    will result in an error, because when it's evaluated, it will look
    to the shell as if there is nothing to the left of the '!=' and
    therefore there's a missing expression in the statement.<br>
    <br>
    This, however, is fine:<br>
    <br>
    [ "$WEBALIZER_CRON" != yes ]<br>
    <br>
    because the quotes ensure that the statement will be evaluated with
    an expression to the left of the != even if the expression is just
    an empty string.<br>
    <br>
    This is fine too:<br>
    <br>
    [ z$WEBALIZER_CRON != zyes ]<br>
    <br>
    because if the variable is empty, the expression to the left will be
    "z" rather than an empty string.<br>
    <br>
    It's unnecessary to use both the quotes <i>and</i> the extra
    character on both sides of the expression. I'm not sure, but I think
    it may have been necessary to use both at some point in the past,
    because I think the middle example above, with just the quotes,
    might actually have been buggy in some old versions of the "test"
    program that evaluates such expressions. This caused shell
    programmers to get into the habit of using both the quotes and the
    extra character. I doubt it's been necessary to do that for many
    years, though for all I know webalizer may support some UNIX
    versions that are so old that they still have problems in this area.
    Given that possibility, there's certainly no harm in writing the
    test the way it's written in the file you looked at.<br>
    <br>
      jik<br>
    <br>
  </body>
</html>