我有脚本
#!/bin/bash
ARR=("a" "b")
collection_init_msg=$( jq -n --arg arr $ARR '{arr: [$arr]}')
echo some command "$collection_init_msg"
Run Code Online (Sandbox Code Playgroud)
应该转换 ARR 并将其打印为 JSON 数组。
当前结果
一些命令 { "arr": [ "a" ] }
我想要的是:
某些命令 { "arr": [ "a", "b" ] }