Config files in bash scripts?
Config files in bash scripts?
am 24.09.2007 23:06:37 von Jables
Is there a good way to read and process a config file in a bash
script. I want global variables defined in a configuration file in
the form variable = value then read into the bash script.
Thanks,
John Brunsfeld
Re: Config files in bash scripts?
am 24.09.2007 23:17:51 von Ed Morton
Jables wrote:
> Is there a good way to read and process a config file in a bash
> script. I want global variables defined in a configuration file in
> the form variable = value then read into the bash script.
>
> Thanks,
> John Brunsfeld
>
In the config file "file":
var1=val1
var2=val2
....
then do this:
. file
Regards,
Ed.
Re: Config files in bash scripts?
am 24.09.2007 23:29:43 von Jables
On Sep 24, 2:17 pm, Ed Morton wrote:
> Jables wrote:
> > Is there a good way to read and process a config file in a bash
> > script. I want global variables defined in a configuration file in
> > the form variable = value then read into the bash script.
>
> > Thanks,
> > John Brunsfeld
>
> In the config file "file":
>
> var1=val1
> var2=val2
> ....
>
> then do this:
>
> . file
>
> Regards,
>
> Ed.
Hmmmmmm, so I just tried that
In a file name file:
var1=1
var2=2
var3=3
Then in a file called run.sh:
.. file
echo $var1
echo $var2
echo $var3
Output:
../run.sh: line 1: ????: command not found
Thanks,
JB
Re: Config files in bash scripts?
am 25.09.2007 00:05:37 von Ed Morton
Jables wrote:
> On Sep 24, 2:17 pm, Ed Morton wrote:
>
>>Jables wrote:
>>
>>>Is there a good way to read and process a config file in a bash
>>>script. I want global variables defined in a configuration file in
>>>the form variable = value then read into the bash script.
>>
>>>Thanks,
>>>John Brunsfeld
>>
>>In the config file "file":
>>
>> var1=val1
>> var2=val2
>> ....
>>
>>then do this:
>>
>> . file
>>
>>Regards,
>>
>> Ed.
>
>
> Hmmmmmm, so I just tried that
> In a file name file:
>
> var1=1
> var2=2
> var3=3
>
> Then in a file called run.sh:
>
> . file
> echo $var1
> echo $var2
> echo $var3
>
> Output:
> ./run.sh: line 1: ????: command not found
>
> Thanks,
> JB
>
"file" is a command you're "dot-executing". Just like executing any
other command, "file" has to be in a directory in your PATH or you need
to specify an explicit path when you invoke it. Change run.sh to:
.. ./file
echo "$var1"
echo "$var2"
echo "$var3"
Regards,
Ed.
Re: Config files in bash scripts?
am 25.09.2007 00:23:19 von Jables
On Sep 24, 3:05 pm, Ed Morton wrote:
> Jables wrote:
> > On Sep 24, 2:17 pm, Ed Morton wrote:
>
> >>Jables wrote:
>
> >>>Is there a good way to read and process a config file in a bash
> >>>script. I want global variables defined in a configuration file in
> >>>the form variable = value then read into the bash script.
>
> >>>Thanks,
> >>>John Brunsfeld
>
> >>In the config file "file":
>
> >> var1=val1
> >> var2=val2
> >> ....
>
> >>then do this:
>
> >> . file
>
> >>Regards,
>
> >> Ed.
>
> > Hmmmmmm, so I just tried that
> > In a file name file:
>
> > var1=1
> > var2=2
> > var3=3
>
> > Then in a file called run.sh:
>
> > . file
> > echo $var1
> > echo $var2
> > echo $var3
>
> > Output:
> > ./run.sh: line 1: ????: command not found
>
> > Thanks,
> > JB
>
> "file" is a command you're "dot-executing". Just like executing any
> other command, "file" has to be in a directory in your PATH or you need
> to specify an explicit path when you invoke it. Change run.sh to:
>
> . ./file
> echo "$var1"
> echo "$var2"
> echo "$var3"
>
> Regards,
>
> Ed.
Thanks, worked like a charm.