Created
April 23, 2014 20:17
-
-
Save jstrassburg/11230788 to your computer and use it in GitHub Desktop.
The worst code I ever wrote
This file contains 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
# This was part of a larger bash script. | |
# I decided to use sed to replace a password in an XML file after prompting the person installing. | |
# Since it was XML I had to first use sed to encode for XML. | |
# Then, since I was using sed I had to encode for sed. | |
# There is some shell encoding there too because of the backticks. | |
# A lot of damn back slashes. | |
# encode for XML | |
# & => & < => < > => > " => " ' => ' | |
ENCODED_SQL_PASSWORD=`echo $SQL_PASSWORD | sed -e "s/&/\&/g" -e "s/</\</g" -e "s/>/\>/g" -e "s/\"/\"/g" -e "s/'/\'/g"` | |
# now encode for sed | |
# \ => \\ " => \" & => \& / => \/ | |
ENCODED_SQL_PASSWORD=`echo $ENCODED_SQL_PASSWORD | sed -e "s/\\\\\/\\\\\\\\\\\\\/g" -e "s/\"/\\\\\\\\\"/g" -e "s/&/\\\\\&/g" -e "s_/_\\\\\/_g"` | |
echo "Using $ENCODED_SQL_PASSWORD" | |
sed -i "s/{PutPasswordHere}/${ENCODED_SQL_PASSWORD}/g" $MY_XML_CONFIG |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment