function readJson {
UNAMESTR=`uname`
if [[ "$UNAMESTR" == 'Linux' ]]; then
SED_EXTENDED='-r'
elif [[ "$UNAMESTR" == 'Darwin' ]]; then
SED_EXTENDED='-E'
fi;
VALUE=`grep -m 1 "\"${2}\"" ${1} | sed ${SED_EXTENDED} 's/^ *//;s/.*: *"//;s/",?//'`
if [ ! "$VALUE" ]; then
echo "Error: Cannot find \"${2}\" in ${1}" >&2;
exit 1;
else
echo $VALUE ;
fi;
}
# Site info from JSON
DOMAIN=`readJson site-info.json domain` || exit 1;
NAME=`readJson site-info.json site-name` || exit 1;
SLUG=`readJson site-info.json slug` || exit 1;
PREFIX=`readJson site-info.json prefix` || exit 1;
DESC=`readJson site-info.json description` || exit 2;
Code language: Bash (bash)
Read JSON files from Bash scripts
by
Leave a Reply