Skip to content

Instantly share code, notes, and snippets.

@skojin
Last active September 4, 2020 15:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save skojin/a24cd8e6384583782afe0e36cc2bbdf4 to your computer and use it in GitHub Desktop.
Save skojin/a24cd8e6384583782afe0e36cc2bbdf4 to your computer and use it in GitHub Desktop.
test input with jq, if ok then show input, otherwise exit with non 0 exit code
#!/bin/sh
# test input with jq, if ok then show input, otherwise exit with non 0 exit code
# echo '{"success": true}' | jq -e '.success | select(. == true)' # => {"success": true}
# echo '{"success": false}' | jq -e '.success | select(. == true)' # => exit code non 0
input=`cat`;
if echo "$input" | jq -e "$1" > /dev/null ; then
echo "$input"
else
exit $?
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment