I'm making a script that will automatically start up (i.e. make the folders and files and stuff) websites for me, but the syntax is killing me. Heres the script:
Code:
#!/bin/bash
param['title']="Test site"
webDir="/var/www/test"
projectName="new_test_site"
projectDirName=${webDir}/${projectName}
mkdir -p $projectDirName
headvar=$(cat template.html | sed -e "s/~*~/${param[*]}/g")
echo $headvar
heres template.html:
HTML Code:
<!DOCTYPE html>
<html>
<head>
<title>~title~</title>
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
as you can see, ~title~ is in the HTML tag, so I need bash to replace it with param['title'], if I do this:
Code:
cat template.html | sed -e "s/~*~/${param['title']}/g"
it works (well kinda does, theres a bit of a glitch though), but I need the matched pattern to be the index of the array, but bash has a special meaning for array[*] so I don't know how. My plan is to have loads of these ~variables~ which bash will replace with values from the params array. Whats the best way of doing this? Would I be better off using awk?
Bookmarks