|
|
|
|
|
by ryapric
696 days ago
|
|
On mobile so no idea if this a) looks good or b) runs (especially considering the command substitutions, but you could also redirect to temp files instead), but it's just something like this: 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. |
|
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!