Date: Thu, 8 Nov 2018 19:38:53 +0100 From: Polytropon <freebsd@edvax.de> To: freebsd-questions@freebsd.org Subject: Re: Append to "command" in rec script Message-ID: <20181108193853.ee1404e2.freebsd@edvax.de> In-Reply-To: <SN1PR20MB2109DD8D5387A977F1F550B480C50@SN1PR20MB2109.namprd20.prod.outlook.com> References: <SN1PR20MB2109DD8D5387A977F1F550B480C50@SN1PR20MB2109.namprd20.prod.outlook.com>
next in thread | previous in thread | raw e-mail | index | archive | help
On Thu, 8 Nov 2018 18:13:24 +0000, Carmel NY wrote: > I am attempting to create an "rc" script to start a program I am working on. > I want, if possible, for the user to enter something in the rc.conf file to be > added to the "command" string when the program is started. > > EXAMPLE: > > In the rc script, this is present > > command=/usr/local/bin/MyProg > > Now, suppose the user wanted to activate logging. They could modify the rc > script and append an "-l" to the command string. However, I would rather they > entered options in the rc.conf file Maybe read "man 5 rc.conf" and put non-FreeBSD (or at least "experimental" stuff) in /etc/rc.conf.local. The difference between rc.conf and rc.conf.local is not as big in FreeBSD as it is in OpenBSD. ;-) > I have been trying to use something like this in the re.conf file: > > MyProg_append="-l" > > is there a way to get the script to automatically append that to the > "command" or would I have to use something like this: > > command=/usr/local/bin/MyProg ${MyProg_append} The common way to do this is to have a _flags variable, for example myprog_flags="-l" You can then execute $command $myprog_flags in the script you're sourcing rc.conf into, and then executing the program with flags, if present. In case you don't have this in place yet, a convenient way to source rc.conf is this: #!/bin/sh if [ -z "${source_rc_confs_defined}" ]; then if [ -r /etc/defaults/rc.conf ]; then . /etc/defaults/rc.conf source_rc_confs elif [ -r /etc/rc.conf ]; then . /etc/rc.conf elif [ -r /etc/rc.conf.local ]; then . /etc/rc.conf.local fi fi # ... your commands here ... This makes sure a certain "precedence" is maintained, if you need that feature. > What happens if the variable is empty? An unset variable will (with sh defaults) evaluate to the empty string. See "man sh" for "-u nounset" if you want to get warnings about unset variables. -- Polytropon Magdeburg, Germany Happy FreeBSD user since 4.0 Andra moi ennepe, Mousa, ...
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20181108193853.ee1404e2.freebsd>