I have this bash script that is basically a search/replace in a text file.
I am running into issues when a user sends in a string that has special characters (quotes, spaces, =s, etc). So I think that I want to put a \ in front of each special character. Can I do it in one command or does each character needs its own command?
Or I am going about this in the wrong way?
Heres the code.
echo "Enter a string to be replaced:"
echo "Enter a string that will replace the above string:"
echo "Enter the name of a file where you want this to take place:"
#Checks to see if the file exists in the current directory
if [ -e $filename ]
#saves a backup of the original file
cat $filename > $oldfile
#makes sure the quotes are read in correctly
#performs the replacement
sed -i 's/'$old'/'$new'/g' $filename
echo "Success! Your file has been updated"
echo "The filename that you typed in does not exist."