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

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 ?? ^^1^^

but more idiomatically and elegantly, you can use a single question mark to examine the exit code of an external command:

* ! ? test -f $HOME/mail/.procmailrc

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.