Solved Problem using a variable in a sed script

I managed to get this working some time ago but can't recall how.

This does not work as I want. I know I need to escape $IP in the sed script. Can someone remind me how?


Code:
#!/usr/bin/env sh                                                                                                                                                                                                                                                      
                                                                                                                                                                                                                                                                       
IP='192.168.1.100'                                                                                                                                                                                                                                                      
                                                                                                                                                                                                                                                                       
echo $IP                                                                                                                                                                                                                                                                
                                                                                                                                                                                                                                                                       
sed 's/^#ServerName.*$/ServerName \$IP/g' httpd.conf.tmp
 
Your single-quotes symbols block variable evaluation, if you still need them for whatever reason, you can use:
Code:
sed 's/^#ServerName.*$/ServerName '$IP'/g' httpd.conf.tmp
 
Back
Top