我有一个shell脚本文件
validation-example.sh
,它有以下内容
expected_template = '{
"remoteIds": [
{
"remoteId": "",
"requestsReceived": 1
},
{
"remoteId": "",
"requestsReceived": 1
},
{
"remoteId": "",
"requestsReceived": 1
},
{
"remoteId": "",
"requestsReceived": 1
}
]
}'
actual_json = '{
"remoteIds": [
{
"remoteId": "[fd00:10:244:1:0:0:0:12]--(http://fd00-10-244-1--12.test.pod:8080)",
"requestsReceived": 1
},
{
"remoteId": "[fd00:10:244:1:0:0:0:12]--(http://fd00-10-244-1--12.test.pod:8081)",
"requestsReceived": 1
},
{
"remoteId": "[fd00:10:244:1:0:0:0:12]--(http://fd00-10-244-1--12.test.pod:8082)",
"requestsReceived": 1
},
{
"remoteId": "[fd00:10:244:1:0:0:0:12]--(http://fd00-10-244-1--12.test.pod:8083)",
"requestsReceived": 1
}
]
}'
validate_json() {
local data="$1"
local template="$2"
jq -e "$data | $template" >/dev/null
}
if validate_json "$actual_json" "$expected_template"; then
echo "The actual JSON matches the expected template."
else
echo "The actual JSON does not match the expected template."
fi
但是,当我运行该文件时,它返回以下错误
validation-example.sh: line 1: expected_template: command not found
validation-example.sh: line 22: actual_json: command not found
jq: error: syntax error, unexpected '|', expecting $end (Unix shell quoting issues?) at <top-level>, line 1:
|
jq: 1 compile error
The actual JSON does not match the expected template.
请帮忙 谢谢