Hello,
I apologize in advance for my limited UNIX scripting knowledge. I am new to it and really want to learn.
I am trying to write a bash script that updates a config file based on user input.
What is the best method for accomplishing this? I need it to prompt the user for two variables, find the location in the config file, and insert new text with the two variables.
I was thinking I could use sed to find the text in the config file where the new text must be inserted before and replace it with the new text, two variables, and same ending text as before. Example:
echo "1st variable?"
read variable1
echo "2nd variable?"
read variable2
sed -e "s|<the spot in the config file that needs new config>|sometext...$variable2_somemoretext...$variable1\n<the spot in the config file that needs new config>|g" config > config2
This works except variable2 is not inserted into the replace string, only variable1 is. This is the result in config2:
sometext..._somemoretext...$variable1
<the spot in the config file that needs new config>
If anyone can tell me why variable2 isn't working in the sed replace string, or if there's a much better way for accomplishing what I'm after, I'd appreciate any help I can get.