#! /bin/bash
key=LIVDSRZULELA #key provided by tenor
url="https://g.tenor.com/v1/search?q=$1&key=$key&limit=$2"
#search key and total results will be given by command arguments
js=$(curl $url) # this have whole json result from tenor
res=$(echo $js | jq '.results[].media[].gif.url') # res contains the url of the gif that we searched
cd $HOME/Desktop/Me/gifs
echo $res # outputs correct URL
curl -O $res # this is giving error
problem is that I cant curl the res vaiable as its showing bad/illegal format kind of error
CodePudding user response:
Add -r
to the jq command (for raw-output). Your code can only handle limit=1
The following worked for me
key=LIVDSRZULELA #key provided by tenor
url="https://g.tenor.com/v1/search?q=$1&key=$key&limit=$2"
#search key and total results will be given by command arguments
url2=$(curl $url | jq -r '.results[].media[].gif.url') # this have whole json result from tenor
curl "$url2"
testit cake 1
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 4301 0 4301 0 0 37504 0 --:--:-- --:--:-- --:--:-- 40196