Jan Pastyřík Jan Pastyřík - 1 year ago 81
Bash Question

Reading variables from config file in Shell

I have question about Linux shell scripts. My question is realy abstract, so may not make sense. The idea is having 1 script and 2 config files.

Script can be like (drinkOutput.sh):


echo -e " $1 \n"
echo -e " $2 \n"

First Config file contain (beer.conf):


Second Config file contain (vine.conf):


The key thing is calling the script. It has to be in next format (or with parameter)

./drinkOutput.sh beer.conf

In this case I need to have in $1 heineken and in $2 argus (inside of drinkOutput script). For

./drinkOutput.sh vine.conf

I need to get back into drinkOutput.sh chardonnay and hibernal.

Does anybody know? Thanks for any tips

Answer Source

You can source the config files if they are in the right format (and it seems it is in your example).

    echo "$1"
    echo "$2"

source "$conf"
drinkOutput "$drink1" "$drink2"
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download