[svlug] bash scripts - config files with comments?

Paul Reiber reiber at gmail.com
Thu Aug 16 20:22:42 PDT 2007


> > the bash command '.' is similar to the csh command 'source' - both
> > take an argument filename, and read that filename into the current
> > script as if the lines of the file were actually part of the
> > 'sourcing' script itself.
>
> No, that's exactly what I'm doing now and what I'm trying to avoid.

Might I ask why?  sourcing a separate configuration file seems to
be exactly what you're looking for, and the shell's parser can
ignore comment lines and white space issues, which is what you
asked for.

> The stuff that Robert L. posted looks promising. I was hoping to avoid
> sed or any other external utility, but hey, if it works then fine -
> after all the config file is only processed once.

A sourced file will only be processed once, assuming you're not
sourcing it from within a loop.  And using the shell's source command
is significantly simpler than reading and parsing lines from a file
programatically; it's a one-liner rather than a complicate loop such
as the one Robert posted.

I'm significantly perplexed by your response - your request was for
something that could read and process a configuration file, and the
shell 'source' commands provide exactly that capability.  Of course,
if you misuse the capability, that's another story.

Hope this helps,
-Paul
http://reiber.org



More information about the svlug mailing list