K
K
ksvdon2014-12-26 14:34:47
linux
ksvdon, 2014-12-26 14:34:47

How to set data from a certain config to a script?

In python, this is done something like this:
There is a config "settings"
in it there are entries like

[root_info]
root_login = root
root_pass = 12345
root_email = [email protected]

[urls_info]
global_url=192.168.0.1

Let's say I want to set ip, passwords, etc. through variables in the script - it's done like this
settings = SafeConfigParser()
settings.read('./settings')

USER = settings.get('root_info', 'root_login')
PASS = settings.get('root_info', 'root_pass')
MYIP = settings.get('urls_info', 'global_url')

then I substitute the USER PASS MYIP variables where I need to...
How can I implement the same thing in bash, so that I can read data into variables from the same config?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
3
3vi1_0n3, 2014-12-26
@3vi1_0n3

In config (script.cfg):

Param1=Value1
Param2=Value2

In the bash script:
. script.cfg

A
Armenian Radio, 2014-12-26
@gbg

#!/bin/bash

    IFS="="
    while read -r name value
    do
         echo "$name is $value"
    done < "config.cfg"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question