The following values ββuse bash printf %q to correctly exclude values ββregardless of their contents. It is guaranteed to handle literally any possible value - quotation marks, newlines, etc., while the shell highlighting its output, bash, and while the operating system used supports the /proc/self/environ tool, first provided by Linux, to emit the contents of the environment as a stream limited to NUL. It uses special quoting forms such as $'\n' as and when necessary, so its output cannot be honored with pure POSIX interpreters.
#!/usr/bin/env bash while IFS= read -r -d '' kvname; do k=${kvname%%=*} v=${kvname#*=} printf '%q=%q\n' "$k" "$v" done </proc/self/environ
Please note that you will need to display the source code, and not run it as an external executable file if you want to change the current shell environment. If you do not want set -a before searching, add the export lead to the format string.
Charles Duffy
source share