procmail
[Top] [All Lists]

Re: quick question

1999-08-24 00:53:06
On Mon, 23 Aug 1999 20:23:07 -0700 (PDT), "S.Toms"
<tomas(_at_)primenet(_dot_)com> wrote:
  I;ve got a really quick question, how can you check to see that a
variable equals something? I'm trying to make sure the variable
isn't empty but I havn't been able to figure out a correct syntax
for it.

You already got some good replies, but here's an additional
observation.

You can use the ${VAR:-something} syntax for this as well. This is
first and foremost a convenient shorthand for setting a variable
conditionally, but it also lets you see the difference between an
unset (never referenced) variable and one which is merely empty.

    USER=${USER:-$LOGNAME}  # set USER to $LOGNAME if it's unset or empty

You can also do something like this:

    # Bail out if VARIABLE is unset

    SETNESSTEST=${VARIABLE+true}

    :0
    * ! SETNESSTEST ?? ^^true^^
    {
        LOG="$_: VARIABLE not set -- exiting prematurely
"       HOST
    }

IMHO it would be nice if there was a facility for returning the empty
string if a variable is set and something else otherwise. This can be
simulated with the existing constructs, of course, but it's cumbersome
(something like the above SETNESSTEST conditional, perhaps. I've been
unable to come up with anything resembling a one-liner). Anyway, this
is missing from the shell as well, not just from Procmail. (The shell
also has ${var?str} and ${var=str} which are of limited usefulness in
Procmail. I guess ${var=str} would sometimes be convenient but it's
really just var=${var-str} in disguise.)

/* era */

-- 
 Too much to say to fit into this .signature anyway: <http://www.iki.fi/era/>
  Fight spam in Europe: <http://www.euro.cauce.org/> * Sign the EU petition

<Prev in Thread] Current Thread [Next in Thread>