Skip to content

Instantly share code, notes, and snippets.

@devopsleigh
Created May 24, 2024 05:49
Show Gist options
  • Save devopsleigh/5283b3c0b62cc560fa630e21dec12f33 to your computer and use it in GitHub Desktop.
Save devopsleigh/5283b3c0b62cc560fa630e21dec12f33 to your computer and use it in GitHub Desktop.
Extracts all variable names from a compose.yml and creates a .env file ready for values to be inserted
#!/bin/bash
# Define the Compose file path
COMPOSE_FILE="compose.yml"
# Define the .env file to create
ENV_FILE=".env"
# Empty the .env file if it already exists
> $ENV_FILE
# Extract the variable names and write them to the .env file
grep -oP '\$\{\K[^}]*' "$COMPOSE_FILE" | sort -u | while read -r var_name; do
echo "$var_name=" >> "$ENV_FILE"
done
echo "The .env file has been created with empty values for the variables."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment