[英]How to get environment variables into a bash array?
In bash, how can I get all environment variables into an array variable? bash,如何把所有的环境变量放到一个数组变量中?
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.
因此,在 EOL 上拆分不会给出预期的结果。
$(...)
expands to a string, and strings can't have zero bytes. $(...)
扩展为一个字符串,并且字符串不能有零字节。
Do not use <<<$(...)
, when you can use < <(...)
.不要使用
<<<$(...)
,当你可以使用< <(...)
。
readarray -d "" env_vars < <(env -0)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.