Skip to content

Instantly share code, notes, and snippets.

@cedricvidal
Created August 22, 2024 14:50
Show Gist options
  • Save cedricvidal/a03518e9417a4a9226c7a8b104b7c60a to your computer and use it in GitHub Desktop.
Save cedricvidal/a03518e9417a4a9226c7a8b104b7c60a to your computer and use it in GitHub Desktop.
Deduplicate environment variables from multiple sources with Bash 4+
#!/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