Created
December 20, 2016 01:55
-
-
Save hungtatai/d95c7e1590ea29ed8102a462c9dddbdc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Get Environment Variable from $FILE and Set to Current Environment | |
function ExtractEnv () { | |
FILE_PATH=$1 | |
ITEM_NAME=$2 | |
VALUE=`cat $FILE_PATH | awk 'BEGIN{FS="="}{ if ($1 ~ /\s*'$ITEM_NAME'\s*/) print $0}' | sed 's/^\s*'$ITEM_NAME'\s*=\s*//'` | |
eval "$ITEM_NAME='$VALUE'" | |
} | |
``` | |
Example: | |
ExtractEnv ./config.sh ROOT | |
echo $ROOT | |
Output: | |
/home/user | |
``` | |
``` | |
config.sh | |
ROOT=/home/user | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment