Hi all,
I'm trying to write a script that will setup a new website on my development box - one that automatically creates its Subversion repository, checks out a local working copy, creates folders for the apache scripts and log files, and updates the apache config. It's all going swimmingly, except for the last bit - automatically updating the apache config. The "template" apache config for each new website is stored in a file with dummy entries where the real values should go (so for instance WEBSITE_NAME will be replaced by a display name for the website), and I'm trying to use sed to replace these values in my script.
Because of what the script is doing, I've added a "debug" mode that echo's the commands to be run, rather than actually running them (so I don't mess up my system), so the commands are run from a variable (for instance $( $cmd )). This bit seems to work fine, except when I try and use sed to update the config file, in which case I get the following error that I haven't been able to resolve after several hours of Googling:
sed: -e expression #1, char 1: unknown command: `''
I've managed to whittle the error down to the following:
Code:
# Create the sed command
cmd="sed 's/WEBSITE_NAME/Test\ With\ Spaces/g' /svn/svn-admin/httpd-conf-skel"
# Try running in a sub-shell
output="$( $cmd )" # Tried both like this...
output="`$cmd`" # ... and in backticks, and both give the above error
# Try piping through bash
output="$( echo "$cmd" | bash )"
echo "$output" # This works!
# Try running manually
sed 's/WEBSITE_NAME/Test\ With\ Spaces/g' /svn/svn-admin/httpd-conf-skel
# This works too!
Naturally removing the spaces and the single quotes from $cmd makes all the little errors go away, but that's not exactly practical in the real world. I've tried quoting the s/// part of the sed command in both single quotes (as above) and double quotes, and the only difference is that the error complains about double quotes instead. So, is there some kind of extra variable substitution/interpolation that occurs when I run it this way, as the command itself works fine when run manually? Or is there something else wrong that is blatantly obvious to everyone but me?
I'm running an up-to-date Fedora 11, with sed version 4.1.5 and bash 4.0.16(1)-release.
Thanks!
PS. For the record, /svn/svn-admin/httpd-conf-skel contains
Code:
# WEBSITE_NAME
<VirtualHost *:80>
DocumentRoot /var/www/html/WWW_DIR/htdocs
ServerName SERVER_NAME
ErrorLog logs/LOG_DIR/error_log
CustomLog logs/LOG_DIR/access_log common
</VirtualHost>