[英]How to parse JSON using shell command
当涉及到 shell 时,我很新,当我使用 Jenkins 调用 function 时,我已经能够做一些简单的事情,例如在我的服务器上创建一个文件。
现在我有一个看起来像这样的命令:
"echo '$store;$url;$id' > /home/flags/start_$id.flag"
这将创建一个包含 store;url;id 信息的文件,示例为:
google;https://www.google.se/;136
但是,我确实想知道如何代替使用; to split and then converting it to a JSON to instead send the shell command straight to a JSON file so I can read the file as JSON. 那可能吗?
我不确定 Jenkins 将如何影响您想要做的事情,但您通常可以通过多种方式编写有效的 json (这当然不是一个详尽的列表,但代表了一些常见的方法):
echo "{\"store\": \"$store\", \"url\": \"$url\", \"id\":\"$id\"}"
echo '{"store": "'"$store"'", "url": "'"$url"'", "id":"'"$id"'"}'
cat << EOF
{"store": "$store", "url": "$url", "id": "$id"}
EOF
上面唯一真正的区别是引用的方式。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.