Oregon Transplant <moseley(_at_)netcom(_dot_)com> writes:
1) What is a simple way to use $? to set a variable if it is not already
defined?
I've tried using recipes, and simple equates like
# Set $VAR if not already set
VAR=`if !($?VAR) echo "value"`
but, obviously, that will clear VAR if already set.
Procmail handles bourne shell style variable expansions (NOT csh, thank god):
# Set VAR to to itself, unless it is unset or empty (in which case set it
# to 'value').
VAR=${VAR:-value}
Also, what is the syntax for a condition?
#deliver to "bad" folder if $VAR undefined
:0:
* $VAR ?? .....
bad
Leave out the dollar sign when doing regexps against variables. And if
you want to actually do what the comment says, try doing this (I *think*
the '^^^^' regexp will work correctly for this):
#deliver to "bad" folder if $VAR undefined
:0:
* VAR ?? ^^^^
bad
2) Is there an cleaner way of doing OR?
# Do something if file.1 OR file.2 doesn't exist
:0i
* ? test -f file.1
* ? test -f file.2
{
}
:0E
| (task to do if either file is missing)
Use weighted conditions:
# How big is infinity? (If the weight total hits this,
# it's an automatic success)
INF=2147483647
# Do something if file.1 OR file.2 doesn't exist
:0
* $INF^0 ? test -f file.1
* $INF^0 ? test -f file.2
The infinity bit just makes it skip any following conditions once it hits
a success.
3) Just to clear up my old memories:
What is the difference between "w" and "W" flags? I try both in
recipes where filter program fail, and I don't see any difference
in the log file. I get 'Program failure' messages in both cases.
1) Are you using a really old version of procmail?
2) Are you sure that procmail was really using the recipe with the
'W' flag?
Also, in a filter I don't need to use the "w" flag if I'm not worried
about a program failure, correct?
Yep.
Philip Guenther
----------------------------------------------------------------
Philip Guenther UNIX Systems and Network Administrator
Internet: guenther(_at_)gac(_dot_)edu Phonenet: (507) 933-7596
Gustavus Adolphus College St. Peter, MN 56082-1498
Source code never lies (it just misleads). (Programming by Purloined Letter?)