Skip to content

Instantly share code, notes, and snippets.

@tolleiv
Last active October 14, 2016 11:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tolleiv/a2b429565b8d7894e83ec4ea784b2095 to your computer and use it in GitHub Desktop.
Save tolleiv/a2b429565b8d7894e83ec4ea784b2095 to your computer and use it in GitHub Desktop.
Compare the amount of opening and closing braces in a file. This can be used as trivial check for Puppet scripts before Puppetlint is used. It might show false positive in case curly braces are embedded in strings.
#!/bin/bash
FILE=$1
function remove_comments {
sed -e 's/#.*$//'
}
OPEN_BRACES=$(cat $FILE | remove_comments | fgrep -o \{ | wc -l)
CLOSE_BRACES=$(cat $FILE | remove_comments | fgrep -o \} | wc -l)
if [ "$OPEN_BRACES" -nq "$CLOSE_BRACES" ]; then
>&2 echo "$FILE has mismatching brace counts.(open: $OPEN_BRACES, close: $CLOSE_BRACES)"
exit 1;
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment