采购ENV输出 [英] sourcing env output
问题描述
我有一些shell code我需要调试,所以我有code抛售它的环境到一个文件
ENV> env.txt
和我的测试脚本,我想它来源,test.sh:
。 ./env.txt
回声$实例
回声$ EXAMPLE2
env.txt的内容是:
例= SH /hello/command.sh
EXAMPLE2 = /只/一些/路径
不过,包膜不把引号围绕其价值,这往往会给$例如,我得到这个错误
一个问题test.sh:/hello/command.sh:找不到
那么清楚它正试图去运行它设置的变量。
你有什么发现针对此问题的解决方法最快?
而读线;做
申报$线
#声明-x$线
#出口$线
完成< env.txt
如果您想要的值导出到环境中,使用 -x
选项声明
或使用导出
命令。
I have some shell code I need to be debug, so I had the code dump its environment into a file
env > env.txt
and with my testing script I want to source it, test.sh:
. ./env.txt
echo $EXAMPLE
echo $EXAMPLE2
the contents of env.txt are:
EXAMPLE=sh /hello/command.sh
EXAMPLE2=/just/some/path
but, env does not put quotes around its values, which tends to cause a issue for $EXAMPLE, I get this error
test.sh: /hello/command.sh: not found
so clearly it is trying to run it instead of setting the variables.
what do you find is the quickest workaround for this problem?
while read line; do
declare "$line"
# declare -x "$line"
# export "$line"
done < env.txt
If you want to export the values to the environment, use the -x
option to declare
or use the export
command instead.
这篇关于采购ENV输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!