Here Document Template Substitution

Generate a config file from a here document template with variable expansion and command substitution.

BashConfig Management

Code

snippet
#!/usr/bin/env bash
set -euo pipefail

APP_NAME="myapp"
PORT="${1:-8080}"
HOSTNAME=$(hostname)

cat > config.yaml <<EOF
app:
  name: ${APP_NAME}
  port: ${PORT}
  host: ${HOSTNAME}
  generated: $(date -u +%Y-%m-%dT%H:%M:%SZ)
EOF

cat config.yaml