From owner-freebsd-hackers Thu Jan 2 17:32:28 2003 Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id A1A2937B401 for ; Thu, 2 Jan 2003 17:32:27 -0800 (PST) Received: from bogslab.ucdavis.edu (bogslab.ucdavis.edu [169.237.68.34]) by mx1.FreeBSD.org (Postfix) with ESMTP id 4292643ED1 for ; Thu, 2 Jan 2003 17:32:27 -0800 (PST) (envelope-from greg@bogslab.ucdavis.edu) Received: from thistle.bogs.org (thistle.bogs.org [198.137.203.61]) by bogslab.ucdavis.edu (8.9.3/8.9.3) with ESMTP id RAA77762 for ; Thu, 2 Jan 2003 17:32:15 -0800 (PST) (envelope-from greg@bogslab.ucdavis.edu) Received: from thistle.bogs.org (localhost [127.0.0.1]) by thistle.bogs.org (8.11.3/8.11.3) with ESMTP id h031VUx83048 for ; Thu, 2 Jan 2003 17:31:30 -0800 (PST) (envelope-from greg@thistle.bogs.org) Message-Id: <200301030131.h031VUx83048@thistle.bogs.org> To: hackers@FreeBSD.ORG X-To: Tim Kientzle X-Sender: owner-freebsd-hackers@FreeBSD.ORG Subject: Re: Reading rc.conf from C programs? In-reply-to: Your message of "Thu, 02 Jan 2003 12:18:55 PST." <3E149EAF.9040100@acm.org> Reply-To: gkshenaut@ucdavis.edu Date: Thu, 02 Jan 2003 17:31:30 -0800 From: Greg Shenaut Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG In message <3E149EAF.9040100@acm.org>, Tim Kientzle cleopede: >Terry Lambert wrote: > >> Tim Kientzle wrote: >>>I'm trying to figure out how to read and use >>>/etc/rc.conf configuration variables from within >>>a C program. >> >> #!/bin/sh >> # Throw all of rc.conf into the environemnet so a C program >> # named "fred" can read any of them with "getenv". >> . /etc/rc.conf >> fred > > >This doesn't work. /etc/rc.conf does not export >its variables to the environment. It only sets them in the >local shell. Try the above where 'fred' is > #!/bin/sh > printenv >and you'll see what I mean. Try using the "set -a" command before reading rc.conf and it will work: #!/bin/sh set -a . /etc/rc.conf exec yourprog Greg Shenaut To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message