Skip to content

Instantly share code, notes, and snippets.

@H2CO3
Created October 12, 2013 06:00
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 H2CO3/6946339 to your computer and use it in GitHub Desktop.
Save H2CO3/6946339 to your computer and use it in GitHub Desktop.
This script appends an automatically generated include guard to a specified header file. Optionally, you can provide a prefix that will be added to the guard macro.
#!/bin/bash
if [ "$#" = "0" ]; then
echo "at least one argument is required"
exit 1
fi
FILE=$1
GUARD="$2$(printf "%s" $FILE | tr '.' '_' | tr '[[:lower:]]' '[[:upper:]]')"
cat <<EOF >> $FILE
#ifndef $GUARD
#define $GUARD
#endif /* $GUARD */
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment