Skip to content

Instantly share code, notes, and snippets.

@jtpaasch
Created July 31, 2013 10:58
Show Gist options
  • Save jtpaasch/6121122 to your computer and use it in GitHub Desktop.
Save jtpaasch/6121122 to your computer and use it in GitHub Desktop.
Reads a file containing an expression of the form KEY=VALUE, and it gets just the VALUE.
#!/bin/bash
# The path to the file.
FILE=/path/to/my/file
# Read the file's contents.
CONFIG_CONTENTS=$(<$FILE)
# Split at the '='.
PARTS=(${CONFIG_CONTENTS//=/ })
# The VALUE will be just the second part.
VALUE=${PARTS[1]}
if [[ -z $VALUE ]]; then
echo "No value."
else
echo "The value is: $VALUE"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment