procmail
[Top] [All Lists]

Re: testing if a variable is EMPTY

1997-01-07 10:23:34
Timothy Luoma asked,

| I'd like to test if a variable has been set but has nothing as its  
| contents.

You want to test for set and empty; unset is no good, and non-empty is no
good.  OK.  There's no need to run any outside programs.  (By the way, the
shell code you posted will not distinguish between unset and null variables.)
This is all you need (and it should not mistake a variable containing only a
newline for null).

  :0
  * $ ! ${VARIABLE+!} ${VARIABLE:+!}
  action

If the variable is unset, "$" interpretation will reduce the recipe to this:

 :0
 * !
 action

and it will fail.

If the variable is set and not null, the recipe will reduce to this:

 :0
 * ! ! !
 action

and it will fail again.

But if the variable is set yet null, the recipe will decode as follows:

 :0
 * ! !
 action

and we're in business.

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