无法 curl 包含 gif url 的变量

Unable to curl a variable that contains url of gif

#! /bin/bash

key=LIVDSRZULELA #key provided by tenor
url="https://g.tenor.com/v1/search?q=&key=$key&limit=" 
#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

问题是我无法卷曲红色变量,因为它显示 bad/illegal 格式错误

-r 添加到 jq 命令(对于 raw-output)。您的代码只能处理 limit=1 以下对我有效

key=LIVDSRZULELA #key provided by tenor
url="https://g.tenor.com/v1/search?q=&key=$key&limit=" 
#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