procmail
[Top] [All Lists]

Re: procmail $DEFAULT problems

1998-08-16 21:29:59
Gregory Sutter asked,

| But if it handles those things, then forks a shell to handle the rest,
| will the ones it set before the shell was called be set in the shell?

Yes.  Procmail exports all normal variables that it sets.  They are known to
any program or shell that it forks and [unless unset or changed by the inter-
vening shell] to any program forked by a shell that procmail forks.

Exceptions are special variables like $_, $$, $?, $1, $2, $*, $@, $-, and the
like.  For example, try these two recipes together:

  :0hfw
  | sed "$ a\\
Procmail's PID for this message was $$.\\
\\
" # the extra \\ line may or may not be needed for your version of sed

  :0hfw
  | cat - ; echo "This shell's PID was $$." ; echo

both should add the new text after the blank line at the neck (forming
the top of the new body).  But the first one contains no characters from
$SHELLMETAS, so procmail will run it itself and use its own PID for $$.
The second invokes a shell, and special variables cannot be exported,
so the shell will use its own value for $$, which will be the shell's
PID, not procmail's.

But ordinary variables are exported.  Try this:

  pid=$$

  :0hfw
  | sed "$ a\\
Procmail's PID for this message was $pid, which equals $$.\\
\\
" # the extra \\ line may or may not be needed for your version of sed

  :0hfw
  | cat - ; echo "This shell's PID was $$ but \$pid was $pid." ; echo

Notice how $$ changes when a shell is invoked but $pid remains the same.

<Prev in Thread] Current Thread [Next in Thread>