Skip to content

Instantly share code, notes, and snippets.

@xmppjingle
Last active July 6, 2016 20:02
Show Gist options
  • Save xmppjingle/a9c3cf3c4063b05b9f6d961cdedc7697 to your computer and use it in GitHub Desktop.
Save xmppjingle/a9c3cf3c4063b05b9f6d961cdedc7697 to your computer and use it in GitHub Desktop.
Cross Platform Shell Based KV Template
#!/bin/bash
#Cross Platform Shell Based KV Template
# Usage: ./iks.sh . VAR1=test VAR2=Temp GOAL=Exceed ROCK=nRoll
# Usage for Mustache {{Keys}}: ./iks.sh . -m VAR1=test VAR2=Temp GOAL=Exceed ROCK=nRoll
MM=false
if [ "$1" = "-m" ]; then
MM=true
shift
fi
DIR=$1
shift
if [ -d "${DIR}" ] ; then
DDIR="$DIR/*"
else
if [ -f "${DIR}" ]; then
DDIR=$DIR
else
echo "${DIR} is not valid";
exit 1
fi
fi
while [ "$#" -gt 0 ]; do
K=`echo $1 | awk -F= '{print $1}'`
V=`echo $1 | awk -F= '{print $2}'`
if [ $MM = true ]; then
sed -i.bak "s/{{$K}}/$V/g" $DDIR
else
sed -i.bak "s/$K/$V/g" $DDIR
fi
rm $DDIR.bak
shift
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment