Skip to content

Instantly share code, notes, and snippets.

@agnaldo4j
Created June 6, 2014 15:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save agnaldo4j/328bec93662abe93d209 to your computer and use it in GitHub Desktop.
Save agnaldo4j/328bec93662abe93d209 to your computer and use it in GitHub Desktop.
Bash script with config file
#!/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