我正在运行以下curl命令:
installer_to_delete=$(curl -s -u username:password "URL/api/search/dates?dateFields=created&from=${Two_Years_Ago}&today&repos=npm-local-lrn" | jq -r '.results[].uri'|sed 's=/api/storage==')
if [[ $installer_to_delete == "" ]]
then
echo "No installers found"
else
for installer in $installer_to_delete
do
echo $installer
done
fi此操作的错误/输出为:
assertion "cb == jq_util_input_next_input_cb" failed: file "/usr/src/ports/jq/jq-1.5-3.x86_64/src/jq-1.5/util.c", line 371, function: jq_util_input_get_position每当Curl命令找不到文件时,它都会显示此输出。当JQ错误找不到文件时,我如何才能使其不弹出?
发布于 2017-12-05 04:38:31
一种(不是很热门的)选项是将STDERR重定向到/dev/null:
jq -r '.results[].uri' 2> /dev/null因为很明显存在错误的可能性,所以更好的选择可能是将管道分成几个步骤,这样您就可以在此过程中根据需要处理不同的错误。
顺便说一句,这个断言表明jq本身存在某种bug。您能给我们展示一下curl的相应输出吗
发布于 2017-12-05 05:12:37
使用curl --fail仅在curl成功时继续运行jq命令:
url="URL/api/search/dates?dateFields=created&from=${Two_Years_Ago}&today&repos=npm-local-lrn"
if result=$(curl -s --fail -u username:password "$url"); then
readarray -t installers < <(jq -r '.results[].uri' <<<"$result" | sed 's=/api/storage==')
if (( ${#installers[@]} )); then
for installer in "${installers_to_delete[@]}"; do
echo "$installer"
done
else
echo "Empty list of installers retrieved" >&2
fi
else
echo "HTTP error retrieving installers" >&2
fihttps://stackoverflow.com/questions/47641412
复制相似问题