Procmail borrows some sh syntax for variable initialisation. Note that available in a procmail rcfile.
VAR1 = ${VAR2:-value} sets VAR1 to VAR2 if VAR2 is set and non-null, and sets VAR1 to default "value" otherwise
VAR1 = ${VAR2-value} sets VAR1 to VAR2 if VAR2 is set, and sets VAR1 to default otherwise
VAR1 = ${VAR2:+value} sets VAR1 to "value" if VAR2 is set and non-null, and sets VAR1 to VAR2 otherwise.
VAR1 =${VAR2+value} Sets VAR1 to "value" if VAR2 is set and sets VAR1 to VAR2 otherwise.
And here are the classic usage examples
VAR = ${VAR:-"yes"} # set VAR to default value "yes" VAR = ${VAR+"yes"} # If VAR contains value, set "yes"
Ever wondered if this calls `date`
in all cases?
VAR = ${VAR:-`date`}
No, procmail is smart enough to skip calling date if VAR already had value. It doesn't evaluate the whole line. Below you see what each initialising operator does. Study it carefully
VAR = "" # Define variable VAR = ${VAR:-"value1"} # VAR = "value1" VAR = "" VAR = ${VAR-"value2"} # VAR = ""
VAR = "" VAR = ${VAR:+"value3"} # VAR = "" VAR = "" VAR = ${VAR+"value4"} # VAR = "value4"
# Note these: VAR = "val" VAR = ${VAR:+"value3"} # VAR = "value3" VAR = "val" VAR = ${VAR+"value4"} # VAR = "value4"
VAR # kill the variable VAR = ${VAR:-"value1"} # VAR = "value1" VAR VAR = ${VAR-"value2"} # VAR = "value2"
VAR VAR = ${VAR:+"value3"} # nothing is assigned VAR VAR = ${VAR+"value4"} # nothing is assigned