Created
May 24, 2024 05:49
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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