- Use
curl
to get the JSON response for the latest release - Use
grep
to find the line containing file URL - Use
cut
andtr
to extract the URL - Use
wget
to download it
curl -s https://api.github.com/repos/jgm/pandoc/releases/latest \
| grep "browser_download_url.*deb" \
| cut -d : -f 2,3 \
| tr -d \" \
| wget -qi -
The
cut
/tr
shenanigans in the original post dodging the colon in the URL drives me crazy. This snippet has propogated everywhere, very few people that copy / paste it know how it works, and it leaves so much room for improvement. @dsifford was on the same track but stopped short of passing the result to the final download. (Edit At first pass I missed @mando7's similar solution, the extragrep -w
flag is a nice touch but not required.)Lets start with swapping
grep | cut | tr
forgrep -o
. If you're already searching for a string, why not just print the bit that matches your search instead of searching for it with context then stripping away the context? No good reason. Since the ".deb" from the original post happens to be ambiguous for this project now I'm including a match.Also, why use two tools
curl
thenwget
whencurl
is arguably more capable than the latter for both jobs.wget -
can becurl -fsSLJO
.If the
grep
doesn't suit you and you havejq
handy you can swap in the equivalent: