Jari Aalto asked,
| What is the best way to init variable conditionally, I just noticed
| that following code will always call shell. I would like to call
| the formail only if the variable is empty. How do I do that?
|
| # If you already have saved the subject, please preset this variable
| # to prevent extra shell call!
| #
| JA_SRV_SUBJECT={JA_SRV_SUBJECT:-`formail -xSubject:`}
Surely Jari must have meant
JA_SRV_SUBJECT=${JA_SRV_SUBJECT:-`formail -xSubject:`}
Anyhow, it shouldn't always call a shell, but it might always call formail.
The solution depends on whether set-but-null is an acceptable value for
the variable. If so,
:0h
* $${JA_SRV_SUBJECT+!}
JA_SRV_SUBJECT=| formail -xSubject:
If not, then there are two approaches:
:0h # note colon in condition line
* $${JA_SRV_SUBJECT:+!}
JA_SRV_SUBJECT=| formail -xSubject:
or
:0h
* JA_SRV_SUBJECT ?? .
JA_SRV_SUBJECT=| formail -xSubject:
You'll also probably want to use formail's -z option if you have a recent
enough version of formail to support it.