Select a method for marking parameters. One of the possibilities is :parameter: but any similar pair of markers that will not be confused with legal text for the template file is good.
Write a sed script (in sed , awk , perl , ...) similar to the following:
sed -e "s/:param1:/$param1/g" \ -e "s/:param2:/$param2/g" \ -e "s/:param3:/$param3/g" \ httpd.conf.template > $HTTPDHOME/etc/httpd.conf
If you get to a situation where you sometimes need to edit something, and sometimes not, it might be easier for you to create the appropriate sed commands in a batch file, and then run this:
{ echo "s/:param1:/$param1/g" echo "s/:param2:/$param2/g" echo "s/:param3:/$param3/g" if [ "$somevariable" = "somevalue" ] then echo "s/normaldefault/somethingspecial/g" fi } >/tmp/sed.$$ sed -f /tmp/sed.$$ httpd.conf.template > $HTTPDHOME/etc/httpd.conf
Note that you should use a trap to ensure that the temporary does not revive its usefulness:
tmp=/tmp/sed.$$ # Consider using more secure alternative schemes trap "rm -f $tmp; exit 1" 0 1 2 3 13 15 # aka EXIT HUP INT QUIT PIPE TERM ...code above... rm -f $tmp trap 0
This ensures that your temporary file is deleted when the script exits for most likely signals. You can save non-zero exit status from previous commands and use exit $exit_status after trap 0 command.
source share