Merging Bash sources

Simon Wistow simon at
Wed Nov 11 01:03:08 GMT 2009

I have a small problem in that I'm trying to modify a bash script so 
that currently does this

    . config
    # then inspect command line args

so that you can specify the config file on the command line. Which 
necessarily requires do

    # inspect command line args first
    . ${config_file}

however that means that anything in the config file will override 
anything passed in on the command line. Which sort of defeats the point. 

Is there an easy way to say "source this config file but don't override 
any variable already set?" or some sort of standard recipe? Or amy I 
going to have to write something that reads the config file line by 
line, splits out any variable name left of a '=' checks to see if it's 
set and then evals the line? Cos that's potentially prone to failure.

More information about the mailing list