Skip to content

Instantly share code, notes, and snippets.

@vicentebolea
Created June 30, 2018 19:00
Show Gist options
  • Select an option

  • Save vicentebolea/fe42e370175aeb462825a6b5e5e1f932 to your computer and use it in GitHub Desktop.

Select an option

Save vicentebolea/fe42e370175aeb462825a6b5e5e1f932 to your computer and use it in GitHub Desktop.
Simple BASH template engine
#!/bin/bash
rules=$1
source $rules
mapfile -t keywords < <(< $1 sed -n 's/^\([A-Za-z0-9_]\+\)=.*$/\1/p')
while read line
do
for keyword in "${keywords[@]}"
do
line=`sed "s@\@${keyword}\@@${!keyword}@g" <<<"$line"`
done
echo $line
done < /dev/stdin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment