Created
August 22, 2024 14:50
-
-
Save cedricvidal/a03518e9417a4a9226c7a8b104b7c60a to your computer and use it in GitHub Desktop.
Deduplicate environment variables from multiple sources with Bash 4+
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 | |
dedup_env() { | |
local -A env_ary | |
while IFS== read -r key value; do | |
value=$(echo "$value" | sed 's/^ *"//' | sed 's/" *$//') | |
env_ary[$key]=$value | |
done <<EOM | |
$(cat $*) | |
EOM | |
for key in ${!env_ary[@]}; do | |
echo "${key}=\"${env_ary[${key}]}\"" | |
done | sort | |
} | |
dedup_env <(azd env get-values) .env.state > .env.state |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment