gpt4 book ai didi

bash - env -0 转储环境。但是如何加载呢?

转载 作者:行者123 更新时间:2023-11-29 08:58:34 25 4
gpt4 key购买 nike

linux命令行工具env可以转储当前环境。

因为有一些特殊字符,我想使用 env -0(每个输出行以 0 字节而不是换行结束)。

但是如何再次加载这个转储呢?

bash 版本:4.2.53

最佳答案

不要使用env;使用 declare -px,它以可以重新执行的形式输出导出变量的值。

$ declare -px > env.sh
$ source env.sh

这也让您可以保存 导出的变量,env 无法访问:只需使用 declare -p(删除 -x 选项)。


例如,如果您编写了 foo=$'hello\nworld'env 会产生输出

foo=hello
world

declare -px 产生输出时

declare -x foo="hello
world"

关于bash - env -0 转储环境。但是如何加载呢?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39118918/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com