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

  • the sond solution works. But I do not understand "? !" – user1888089 Mar 15 '14 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 '14 at 12:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.