Skip to content

Instantly share code, notes, and snippets.

@KylePDavis
Created February 13, 2014 02:56
Show Gist options
  • Select an option

  • Save KylePDavis/8968931 to your computer and use it in GitHub Desktop.

Select an option

Save KylePDavis/8968931 to your computer and use it in GitHub Desktop.

Revisions

  1. KylePDavis created this gist Feb 13, 2014.
    10 changes: 10 additions & 0 deletions sh_template_template.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    #!/bin/bash
    # Template bash script using given script file as source for variable values
    if [ -f "$1" ]; then source "$1" || echo "#! ERROR: Unable to read variables from script: $1!" 1>&2 && exit 1; fi
    (awk '/TMPL$/,/^TMPL/{print}' "$0" | grep -Eio '(^|[^\])\${?[A-Z][A-Z0-9_]*}?' | cut -c3- | tr -d '{}' | sort -u) | grep -v -w -F "$(env | cut -f1 -d= | sort)" | sed 's/^/ERROR: need tmpl var: /' | grep . && exit 123 || true
    ###############################################################################
    cat<<TMPL
    # Config generated on $(date)
    HOST=$SOME_HOST
    FILES="$(ls -1 | paste -sd,)"
    TMPL