There are almost 100 *_flags variables in /etc/defaults/rc.conf and
each holds a set of options processed by getopts in one way or
another. The temptation to manage these *_flags variables with the
list operator += leads to potentially unexpected behavior.
For example, let's say you have in rc.conf:
cron_flags="$cron_flags -j 15"
Executing sysrc cron_flags+="-J 15" to set rootjitter to 15 will
instead result in:
cron_flags="$cron_flags -j 15 -J"
That's because += is not a string append operation but a list add
operation that adds -J but, seeing that 15 is already in the space-
delimited "list," does not add "15".
Despite the fact that one could rely on the fact that getopts allows
-J15 in place of -J 15, we should probably just allow for string
append operations.
Borrowing the .= string-append operator from Perl, this implements
a method to conveniently append text to a string value such as all
the *_flags variables. Executing sysrc cron_flags.="-J 15" would
result in:
cron_flags="$cron_flags -j 15 -J 15"
As a matter of convenience, a single space is added after a non-NULL
value. If you need to append directly to the value without a space,
you can force the use of any delimiter (or no delimiter) by first
collecting the raw value and then setting it in the desired manner.
For example:
cur=$( sysrc -inr foo )
sysrc foo="$cur${cur:+,}extra"
The above has always worked and continues to work. The new .=
operator is equivalent to:
cur=$( sysrc -inr foo )
sysrc foo="$cur${cur:+ }extra" # same as sysrc foo.=extra