#! /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
问题是我无法卷曲可用的,因为它显示了错误/非法格式的错误
将-r
添加到jq命令中(用于原始输出(。你的代码只能处理limit=1
以下对我有效
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