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
}
Max Muster
  • 337
  • 2
  • 6
  • 27

1 Answers1

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.

tripleee
  • 1,416
  • 3
  • 15
  • 24
  • the sond solution works. But I do not understand "? !" – Max Muster 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