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.

Avinash Raj
  • 3,703

2 Answers2

1

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

. local/setenv.sh
thiagowfx
  • 1,249
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
Rakib
  • 2,435