Hi all, On Thu, Jan 02, 2003 at 09:56:16PM +0100, [EMAIL PROTECTED] wrote: > In message <[EMAIL PROTECTED]>, [EMAIL PROTECTED] wri > tes: > >Well, perhaps I'm missing something here, but can't you just tokenize the items > >in rc.conf using strtok after opening up the file in your C program? > > Only if you parse and evaluate the entire /bin/sh syntax.
So, I've come up with the following. With 'env -' you can clear all environment variables, with 'set -a' you can mark all shell variables as exported and with '. /etc/rc.conf' or '. /etc/defaults/rc.conf' you can suck in those variables into a shell. Put this all together into: env - sh -ac '. /etc/defaults/rc.conf; /usr/bin/printenv' and parse the output of that. If you are worried about special characters (notably newlines) in the output of printenv, you can grab my own version of printenv at ftp://ftp.psconsult.nl/pub/src/myprintenv/myprintenv.c and put the binary in /usr/local/bin. Then change the above command in: env - sh -ac '. /etc/defaults/rc.conf; /usr/local/bin/myprintenv -q' Myprintenv -q puts double quotes around the value of each variable and precedes the following characters by a backslash: "\$` Parsing this output should not be that difficult and is unambiguous with regards to special characters. The only caveat is special characters in variable names but '. /etc/defaults/rc.conf' will take care of that. Hope this helps. If people think that -q is a good option for printenv, I can come up with a patch for the standard printenv. Opinions? -- Paul Schenkeveld, Consultant PSconsult ICT Services BV To Unsubscribe: send mail to [EMAIL PROTECTED] with "unsubscribe freebsd-hackers" in the body of the message