Re: Quick fun question: only set an rc.d variable sometimes?

From: Miroslav Lachman <>
Date: Tue, 28 Sep 2021 11:59:42 UTC
On 28/09/2021 05:23, Dan Mahoney (Gushi) wrote:
> Hey all,
> I'm dealing with rc.d scripting and reading 
> Here's my question: Is there a sane way to have something like foo_pid 
> *completely unset* in one case, but overridable by rc.conf after?
> It took me a bit to wrap my head around the:
> : ${dummy_enable:=no}
> : ${dummy_msg="Nothing started."}
> Examples.  (Why that first colon, what is this := syntax), etc.

The first colon is builtin function same as /bin/true

A useful application for : is if you're only interested in using 
parameter expansions for their side-effects rather than actually passing 
their result to a command.
You can use the parameter expansion as an argument to :

: "${var:=$1}"

There is as many variants to handle this as many rc scripts are 
installed on your system. Each have it slightly different (syntax) but 
with the same meaning:

[ -z "$apache24_enable" ]       && apache24_enable="NO"
[ -z "$apache24limits_enable" ] && apache24limits_enable="NO"
[ -z "$apache24limits_args" ]   && apache24limits_args="-e -C daemon"
[ -z "$apache24_http_accept_enable" ] && apache24_http_accept_enable="NO"
[ -z "$apache24_configcheck_disable" ] && apache24_configcheck_disable="NO"

: ${amavisd_enable:=NO}

# default name to "dhcpd" if guessing failed
# Trailing semicolon also for service(8)'s benefit:
name="${name:-dhcpd}" ;

Some more explanation:

To get the assigned value, or default if it's missing:


Or to assign default to VARIABLE at the same time:


Or check the link

> What I'm trying to say in rc.subr language is:
> If the user has set something in rc.conf, use it.  Otherwise, leave it 
> TOTALLY UNSET.  Not to the null string.  Undefined.

Easily readable syntax can be like this:

[ -n "$kdc_pid" ] && pidfile="$kdc_pid"

Variable pidfile will be set to a value of $kdc_pid only if $kdc_pid is 
set and is not empty.

Miroslav Lachman