Skip to content

Instantly share code, notes, and snippets.

@drscream
Created January 20, 2015 14:26
Show Gist options
  • Save drscream/0db2bb944e23232f9114 to your computer and use it in GitHub Desktop.
Save drscream/0db2bb944e23232f9114 to your computer and use it in GitHub Desktop.
#!/bin/bash
configfile='/tmp/myconfig.cfg'
configfile_secured='/tmp/myconfig_secured.cfg'
# check if the file contains something we don't want
if egrep -q -v '^#|^[^ ]*=[^;]*' "$configfile"; then
echo "Config file is unclean, cleaning it..." >&2
# filter the original to a new file
egrep '^#|^[^ ]*=[^;&]*' "$configfile" > "$configfile_secured"
configfile="$configfile_secured"
fi
# now source it, either the original or the filtered variant
source "$configfile"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment