Is quoting necessary in /etc/rc.conf ?

Polytropon freebsd at edvax.de
Sun Aug 6 13:31:41 UTC 2017


On Sun, 6 Aug 2017 11:00:03 +0000, Manish Jain wrote:
> On my system, it works whether I put either of the following in rc.conf:
> 
> xyz_enable="YES"
> 
> Or,
> 
> xyz_enable=YES
> 
> Just wished to check whether an unquoted YES is completely equivalent 
> (and accepted) as a quoted YES ?

Keep in mind /etc/rc.conf is basically a sh script. So the
quoting rules of sh apply, and especially for the values YES
and NO, it's completely equivalent.

The general form is NAME=VALUE, and if VALUE contains spaces,
quoting is needed, except you escape spaces. So

	foo_enable=YES

is totally valid (no spaces), while both

	foo_flags="bar baz"

and

	foo_flags=bar\ baz

is valid as well (with spaces).

If VALUE contains the $ sign or other special characters that
might cause interpretation by /bin/sh at "parsing time", using
the single quotes is possible:

	foo_currency='US$'

For empty values, using

	foo_flags=""

instead of

	foo_flags=

looks "more logical", as "the empty value" can clearly be seen,
instead of just missing the right-hand side of the association.

In order to avoid confusion, using quotes for all arguments is
suggested as per /etc/defaults/rc.conf ("system standard"), and
this consistent form - even for the values that don't _require_
quotes, provides a clean view of that configuration file.

That said, sticking with the "system standard" is never wrong. :-)


-- 
Polytropon
Magdeburg, Germany
Happy FreeBSD user since 4.0
Andra moi ennepe, Mousa, ...


More information about the freebsd-questions mailing list