I want to check with procmail if a file exists and depending on this set DROPPRIVS=yes if its not true stay with DROPPRIVS=no
Why is this not working?
:0 w
* `test -f $HOME/mail/.procmailrc` ?? 1
{
DROPPRIVS=yes
}
I want to check with procmail if a file exists and depending on this set DROPPRIVS=yes if its not true stay with DROPPRIVS=no
Why is this not working?
:0 w
* `test -f $HOME/mail/.procmailrc` ?? 1
{
DROPPRIVS=yes
}
First off, the output from test
is nothing at all, so the backticks will capture an empty string; presumably, you actually want to capture the exit code from test
, not the output.
But anyway, backticks are not valid in a condition. You could use backticks outside of a condition and compare the result, or the exit code, to a variable:
EXISTS=`test -f $HOME/mail/.procmailrc`
EXITCODE=$?
:0
* EXITCODE ?? ^^1^^
{ DROPPRIVS=yes }
but more idiomatically and elegantly, you can use a single question mark to examine the exit code of an external command:
:0w
* ! ? test -f $HOME/mail/.procmailrc
{ DROPPRIVS=yes }
The !
negates the condition, so any non-zero exit code triggers the action.