what I want to acomplish is:
1.) Having a config file as template, with variables like $version $path (for example apache config)
2.) Having a shell script that "fills in" the variables of the template and writes the generated file to disk.
Is this possible with a shell script. I would be very thankfull if you can name some commands/tools I can accomplish this or some good links.
Best Answer
This is very possible. A very simple way to implement this would be for the template file to actually be the script and use shell variables such as
You could even make this configurable on the command line by specifying
version=$1
andpath=$2
, so you can run it likebash script /foo/bar/baz 1.2.3
. The-
before EOF causes whitespace before the lines be ignored, use plain<<EOF
if you do not want that behavior.Another way to do this would be to use the search and replace functionality of sed
which would replace each instance of the strings VERSION and PATH. If there are other reasons those strings would be in the template file you might make your search and replace be VERSION or %VERSION% or something less likely to be triggered accidentally.