0

I want to export all the variables located in a .conf. So I followed this https://unix.stackexchange.com/a/79077/56901 answer.

setenv.sh

#!/usr/bin/env bash
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

set -a
. "$DIR/settings.conf"
set +a

settings.conf

DB_ENV_USER="root"
DB_ENV_PASS="avi"
DB_ENV_NAME="s2s"
TEST_DB_ENV_NAME="testdb"

What I have tried is,

avi:~/project/_backend$
bash local/setenv.sh
avi:~/project/_backend$
echo $DB_ENV_USER

avi:~/project/_backend$

So it failed to show $DB_ENV_USER value root.

1

Your script works just fine. You just have to source it instead of running it:

. local/setenv.sh
1

First you read the link

What is the difference between sourcing ('.' or 'source') and executing a file in bash?

then you source the script

source local/setenv.sh

Not the answer you're looking for? Browse other questions tagged or ask your own question.