Bash Scripting Patterns and Practical Recipes/Generate config with variable expansion

Create small config files from shell variables.

Section: Automation Recipes

Generate config with variable expansion

bash
bash
cat > app.env <<EOF
APP_ENV=${APP_ENV:-dev}
PORT=${PORT:-3000}
EOF
Explanation

Common in local setup scripts and container entrypoints.

Learn the surrounding workflow

Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.

Related commands

Same sheet · prioritizing Automation Recipes
Retry command with delay
Retry a command several times before giving up.
OpenIn sheetbashsame section
Bound command runtime
Stop a command if it runs too long.
OpenIn sheetbashsame section
Run two jobs in parallel and wait
Start jobs in background and wait for both.
OpenIn sheetbashsame section
Use Bash with jq safely
Combine Bash with jq for reliable JSON parsing.
OpenIn sheetbashsame section
Portable Bash shebang
Use env to locate Bash on PATH.
Create temp file
Create a secure temporary file.