Created
July 31, 2013 10:58
-
-
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.
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 | |
# 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