Last active
October 14, 2016 11:54
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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