I am having a shell script file validation-example.sh
, it has the followign content
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
However when i run the file it is returning the following error
validation-example.sh: line 1: expected_template: command not foundvalidation-example.sh: line 22: actual_json: command not foundjq: error: syntax error, unexpected '|', expecting $end (Unix shell quoting issues?) at <top-level>, line 1: | jq: 1 compile errorThe actual JSON does not match the expected template.
any help pleasethanks