I have the following script named export.sh
:
#!/bin/bash
SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
SOURCE="$(readlink "$SOURCE")"
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
done
SOURCE=$(dirname ${SOURCE})
export $(cat "${SOURCE}/../params.env" | xargs)
In some words what it does it to export enviromental variables from a file named params.env
that is located by convention on the prarent folder and exports the contents as enviromental variables.
Sample contents of params.env
file are:
SOMEVAR="val1"
SOMEVAR2="val2"
And a successfull run will provide me SOMEVAR
with value val1
and SOMEVAR2
with value val2
enviromental variables.
But if I run:
./export.sh
And afterwards
printenv | grep SOMEVAR
It does not show that the enviromental variable is set.