Created
June 6, 2014 15:10
-
-
Save agnaldo4j/328bec93662abe93d209 to your computer and use it in GitHub Desktop.
Bash script with config file
This file contains 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
#!/bin/bash | |
set -e #stops the execution of a script if a command or pipeline has an error | |
CONFIG_FILE=/usr/share/cnc/jobprocessor.cfg | |
function trim() { | |
local LVAR=$1; | |
LVAR="${LVAR#"${LVAR%%[![:space:]]*}"}"; # remove leading whitespace characters | |
LVAR="${LVAR%"${LVAR##*[![:space:]]}"}"; # remove trailing whitespace characters | |
echo -n "$LVAR"; | |
} | |
while read LINE; do | |
if [[ "$LINE" =~ ^[^#]*= ]]; then | |
VAR_NAME=$(trim "${LINE%%=*}"); | |
VAR_VALUE=$(trim "${LINE#*=}"); | |
case "$VAR_NAME" in | |
gpg_passphrase) | |
PASS=$VAR_VALUE; | |
;; | |
access_key) | |
KEY=$VAR_VALUE; | |
;; | |
esac; | |
fi | |
done <"$CONFIG_FILE"; | |
echo $PASS | |
echo $KEY | |
#####Config file content####### | |
pg_passphrase=teste | |
access_key=novo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment