From owner-freebsd-questions@freebsd.org Thu Nov 8 18:39:02 2018 Return-Path: Delivered-To: freebsd-questions@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id BA09A1100B63 for ; Thu, 8 Nov 2018 18:39:02 +0000 (UTC) (envelope-from freebsd@edvax.de) Received: from mout.kundenserver.de (mout.kundenserver.de [212.227.126.135]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "mout.kundenserver.de", Issuer "TeleSec ServerPass DE-2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 5E1CB8BD10 for ; Thu, 8 Nov 2018 18:39:01 +0000 (UTC) (envelope-from freebsd@edvax.de) Received: from r56.edvax.de ([92.193.180.181]) by mrelayeu.kundenserver.de (mreue010 [212.227.15.167]) with ESMTPA (Nemesis) id 1MOi1H-1g9eGg1Hjz-00QEOk for ; Thu, 08 Nov 2018 19:38:53 +0100 Date: Thu, 8 Nov 2018 19:38:53 +0100 From: Polytropon To: freebsd-questions@freebsd.org Subject: Re: Append to "command" in rec script Message-Id: <20181108193853.ee1404e2.freebsd@edvax.de> In-Reply-To: References: Reply-To: Polytropon Organization: EDVAX X-Mailer: Sylpheed 3.1.1 (GTK+ 2.24.5; i386-portbld-freebsd8.2) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Provags-ID: V03:K1:cU0fMCaRjQ6KGahxWu+yMrCvSVYBQHzROz64DQjubcI551+RnfJ H3oM6oOhRjdbF2W2ErL0gqNZX0gUKK2BWv/TGuO6r1lmfTyowLKd6IarXJyFnqDJLhBNRh3 th+07c4VI1Ctl/gDIWLZvDEp9TyZPsmFJBZ7WrcZ5IPQ4w8C9bOXTZvaxGSInVRwdZZHm/J ITz4KppMnr9KK4gDveJLA== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V01:K0: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und.de,mx01.schlund.de]; FROM_EQ_ENVFROM(0.00)[]; R_DKIM_NA(0.00)[]; RCVD_TLS_LAST(0.00)[]; ASN(0.00)[asn:8560, ipnet:212.227.0.0/16, country:DE]; IP_SCORE(0.07)[ipnet: 212.227.0.0/16(-0.27), asn: 8560(0.62), country: DE(-0.01)]; RECEIVED_SPAMHAUS_PBL(0.00)[181.180.193.92.zen.spamhaus.org : 127.0.0.10]; ARC_NA(0.00)[]; REPLYTO_EQ_FROM(0.00)[]; FROM_HAS_DN(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; NEURAL_SPAM_SHORT(0.91)[0.915,0]; MIME_GOOD(-0.10)[text/plain]; PREVIOUSLY_DELIVERED(0.00)[freebsd-questions@freebsd.org]; AUTH_NA(1.00)[]; NEURAL_SPAM_MEDIUM(0.21)[0.211,0]; RCPT_COUNT_ONE(0.00)[1]; DMARC_NA(0.00)[edvax.de]; NEURAL_SPAM_LONG(0.76)[0.761,0]; RCVD_IN_DNSWL_NONE(0.00)[135.126.227.212.list.dnswl.org : 127.0.5.0]; MID_CONTAINS_FROM(1.00)[]; R_SPF_NA(0.00)[]; RCVD_COUNT_TWO(0.00)[2] X-Rspamd-Server: mx1.freebsd.org X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 08 Nov 2018 18:39:03 -0000 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, ...