I am using a bash script to install and configuration an application. I am trying to use a template where I can fill in values from variables and then save it to its proper location. This works fine with just variables, but I am unable to use any conditionals. Are there any better ways of doing this?
Heres my example template:
#!/bin/bash
cat <<EOF
DEFAULTS: &DEFAULTS
adapter: $DB
host: $DB_HOST
username: $DB_USER
password: $DB_PASS
database: $DB_DATABASE
if [ ! $DB_RECONNECT = ""]; then
reconnect: $DB_RECONNECT
fi
if [ ! $DB_TIMEOUT = ""]; then
timeout: $DB_TIMEOUT
fi
EOF
And then I use source template.sh > /path/to/file to evaluate and save the file.
cated file to execute? That's what your doing right?, except that the source of the file tocatis provided by the<<EOFhere-document. So why not follow yoursource template > filewithchmod 755 file; ./fileto execute the logic inside?