In bash, how can I get all environment variables into an array variable?
I tried the following:
readarray -d "" env_vars <<< "$(env -0)"
This fails with
-bash: warning: command substitution: ignored null byte in input
Note that an environment variable may contain a multi-line string. Therefore splitting on EOL does not give the desired result.
$(...)
expands to a string, and strings can't have zero bytes.
Do not use <<<$(...)
, when you can use < <(...)
.
readarray -d "" env_vars < <(env -0)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.