Date: Wed, 31 Oct 2012 21:24:26 +0000 (UTC) From: Eitan Adler <eadler@FreeBSD.org> To: doc-committers@freebsd.org, svn-doc-all@freebsd.org, svn-doc-head@freebsd.org Subject: svn commit: r39880 - head/en_US.ISO8859-1/articles/rc-scripting Message-ID: <201210312124.q9VLOQGC033947@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: eadler Date: Wed Oct 31 21:24:26 2012 New Revision: 39880 URL: http://svn.freebsd.org/changeset/doc/39880 Log: Bring the RC article up to date. PR: docs/172692 Submitted by: crees Reviewed by: Michael Telahun Makonnen <mmakonnen@gmail.com> Approved by: bcr (mentor) Modified: head/en_US.ISO8859-1/articles/rc-scripting/article.xml Modified: head/en_US.ISO8859-1/articles/rc-scripting/article.xml ============================================================================== --- head/en_US.ISO8859-1/articles/rc-scripting/article.xml Wed Oct 31 12:55:35 2012 (r39879) +++ head/en_US.ISO8859-1/articles/rc-scripting/article.xml Wed Oct 31 21:24:26 2012 (r39880) @@ -400,8 +400,8 @@ start_cmd="${name}_start" stop_cmd=":" load_rc_config $name<co id="rcng-confdummy-loadconfig"/> -eval "${rcvar}=\${${rcvar}:-'NO'}"<co id="rcng-confdummy-enable"/> -dummy_msg=${dummy_msg:-"Nothing started."}<co id="rcng-confdummy-opt"/> +: ${dummy_enable:=no} <co id="rcng-confdummy-enable"/> +: ${dummy_msg="Nothing started."}<co id="rcng-confdummy-opt"/> dummy_start() { @@ -448,7 +448,7 @@ run_rc_command "$1"</programlisting> system, you should add a default setting for the knob to <filename>/etc/defaults/rc.conf</filename> and document it in &man.rc.conf.5;. Otherwise it is your script that - should provide a default setting for the knob. A portable + should provide a default setting for the knob. The canonical approach to the latter case is shown in the example.</para> <note> @@ -479,7 +479,7 @@ run_rc_command "$1"</programlisting> <important> <para>The names of all &man.rc.conf.5; variables used exclusively by our script <emphasis>must</emphasis> - have the same prefix: <envar>${name}</envar>. For + have the same prefix: <envar>${name}_</envar>. For example: <envar>dummy_mode</envar>, <envar>dummy_state_file</envar>, and so on.</para> </important> @@ -487,19 +487,10 @@ run_rc_command "$1"</programlisting> <note> <para>While it is possible to use a shorter name internally, e.g., just <envar>msg</envar>, adding the unique prefix - <envar>${name}</envar> to all global names introduced by + <envar>${name}_</envar> to all global names introduced by our script will save us from possible collisions with the &man.rc.subr.8; namespace.</para> - <para>As long as an &man.rc.conf.5; variable and its - internal equivalent are the same, we can use a more - compact expression to set the default value:</para> - - <programlisting>: ${dummy_msg:="Nothing started."}</programlisting> - - <para>The current style is to use the more verbose form - though.</para> - <para>As a rule, <filename>rc.d</filename> scripts of the base system need not provide defaults for their &man.rc.conf.5; variables because the defaults should @@ -512,7 +503,11 @@ run_rc_command "$1"</programlisting> <callout arearefs="rcng-confdummy-msg"> <para>Here we use <envar>dummy_msg</envar> to actually - control our script, i.e., to emit a variable message.</para> + control our script, i.e., to emit a variable message. + Use of a shell function is overkill here, since it only + runs a single command; an equally valid alternative is:</para> + + <programlisting>start_cmd="echo \"$dummy_msg\""</programlisting> </callout> </calloutlist> </sect1>
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201210312124.q9VLOQGC033947>