(no title)
ryapric | 1 year ago
N=0
while read -r URL; do
data="$(curl "$URL")" || { printf 'error fetching data\n' && exit 1 ; }
prop="$(jq '.data[].someProp' <<< "$data" || { printf 'error parsing JSON response\n' && exit 1 ; }
grep -v "filter" <<< "$prop" > "$N.data" || { printf 'error searching for filter text\n' && exit 1 ; }
N="$((N+1))"
done < ./links.txt
bash also has e.g. functions, so you could abstract that error handling out. Like I said, not that weird.Edit: oh good, at least the formatting looks ok.
theamk|1 year ago
And yes, you can fix those pretty easily.. as long as you aware about them. But this is a great illustration why you have to be careful with bash: it's a 6-line program which already has 2 bugs which can cause data corruption. I fully agree with the other commenter: switch to python if you have any sort of complex code!
1-more|1 year ago
Too|1 year ago
ryapric|1 year ago