Two stupid examples.
A function with tab formatted VHost output:
addVH() { echo -en "\n<VirtualHost ip address>\n\tDocumentRoot /export/www/$1/html\n\tphp_flag log_errors on\n\tphp_value error_log /export/www/$1/logs/php_error.log\n\tServerName $1\n\tErrorLog /export/www/$1/logs/error.log\n\tCustomLog /export/www/$1/logs/access.log \"combined\"\n\tHostNameLookups off\n</VirtualHost>\n"; }
It takes domain name as single arg so you can do "addVH someDomain >> /some/config/file".
A "here" document:
Code:
DOMAIN="microsoft.com"
cat << EOL >> /some/config/file
<VirtualHost ip address>
DocumentRoot /export/www/$DOMAIN/html
php_flag log_errors on
php_value error_log /export/www/$DOMAIN/logs/php_error.log
ServerName $DOMAIN
ErrorLog /export/www/$DOMAIN/logs/error.log
CustomLog /export/www/$DOMAIN/logs/access.log "combined"
HostNameLookups off
</VirtualHost>
EOL
Functions are good for repetitive things. Since they group code in blocks make code readable as well, use local variables and as bonus you get $FUNCNAME which comes in handy when reporting errors or progress (like 'echo "${0//*\//}: FATAL in ${FUNCNAME}()"').