Skip to content

Instantly share code, notes, and snippets.

@jdhuntington
Created May 4, 2016 18:45
Show Gist options
  • Save jdhuntington/4515c2af01e4c6119eb18609643ee176 to your computer and use it in GitHub Desktop.
Save jdhuntington/4515c2af01e4c6119eb18609643ee176 to your computer and use it in GitHub Desktop.
templating with bash
Top of file {
foo;
bar;
}
serverlist {
__SERVERLIST__
}
And more stuff...%
#!/bin/bash
set -uex
COMPILED_SERVER_LIST=""
NEWLINE=$'\\n'
for var in ${@}
do
NEXT_LINE="upstream_server ${var};"
COMPILED_SERVER_LIST="${COMPILED_SERVER_LIST}${NEXT_LINE}${NEWLINE}"
done
cat nginx.conf | sed -e "s/__SERVERLIST__/${COMPILED_SERVER_LIST}/g" > nginx.conf.compiled
./setup.sh foo 10.0.0.4 10.0.0.5 10.0.0.6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment