0

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
}
2

1 Answer 1

1

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.

2
  • the sond solution works. But I do not understand "? !"
    – Max Muster
    Mar 15, 2014 at 10:29
  • ? means examine exit code and ! inverts the truth value. test -f is true when the file exists, but we want truth (successful condition) when it doesn't.
    – tripleee
    Mar 15, 2014 at 12:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .