Skip to content

Instantly share code, notes, and snippets.

@mahdilamb
Created January 15, 2026 20:13
Show Gist options
  • Select an option

  • Save mahdilamb/577c4b61d35cdb46a84c82054acc6c91 to your computer and use it in GitHub Desktop.

Select an option

Save mahdilamb/577c4b61d35cdb46a84c82054acc6c91 to your computer and use it in GitHub Desktop.
Export specific values
#!/usr/bin/env bash
ALLOWED_VALUES=("$@")
while IFS='=' read -r key value; do
[[ -z "$key" || "$key" =~ ^# ]] && { echo "$key"; continue; }
if [ "${#ALLOWED_VALUES[@]}" -eq 0 ]; then
echo "$key=$value"
continue
fi
for allowed in "${ALLOWED_VALUES[@]}"; do
if [[ "$key" == *"$allowed"* ]]; then
echo "$key=$value"
continue 2
fi
done
echo "$key="
done < .env
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment