macOS ships with Bash 3.2 which doesn't support 'declare -A' (associative arrays).
Replace the 'seen' associative array with a simple delimited string 'seen_keys'
to track which environment variables have been processed.
The logic remains identical:
- String concatenation instead of array assignment
- Substring match instead of array key lookup
Tested on macOS with Bash 3.2.57 and the upsert_env function works correctly.