就像my previous thread一样,我知道如何解析带空格的简单json.
现在我有另一个问题,如果我有多个模块 struct ,它们的键是相同的,但值是不同的,I want the output value to be a combination of the values in each module, but actually the value in the last module will overwrite the previous one.
我的测试样例JSON如下:
{
"WorkspaceName":"aaa bbb ccc ddd eee",
"ReportFileName":"xxx yyy zzz",
"StageName":"sit uat prod"
},
{
"WorkspaceName":"1111 2222 3333 4444 5555",
"ReportFileName":"6666 7777 8888",
"StageName":"sit1 uat1 prod1"
}
我try 过的shell 脚本mian.sh
如下:
InitialFile=$WORKSPACE/deployment/configuration/Initial.json
eval $(sed -n -e 's/^.*"\(.*\)":\(".*"\).*$/\1=\2/p' $InitialFile)
ConfigFile="$WorkspaceName"_"$ReportFileName"
echo The Config File is_$ConfigFile
结果始终是The Config File is_1111 2222 3333 4444 5555_6666 7777 8888
,我希望同时获得两个值:aaa bbb ccc ddd eee_xxx yyy zzz
和1111 2222 3333 4444 5555_6666 7777 8888
.
我如何实现这一点?
来了解一下我为什么要这么做,以及我的一些局限性:
我正在Jenkins上执行我的管道,它将执行我的mian.sh.因此,条目是mian.sh.此外,Jenkins服务器由单独的团队维护,我们不能直接访问服务器,因此不能直接在服务器上运行shell 代码.
另外,我需要组合变量,以便使用该变量来匹配相应配置文件的名称.不同的结果需要匹配不同的文件以进行后续测试.