wget收到“ Scheme missing”错误


14

我编写了一个小脚本,该脚本从Desktoppr API中获取随机墙纸并将其更改为以下墙纸:

#!/bin/bash
url=$(curl 'https://api.desktoppr.co/1/wallpapers?page='$(shuf -i 1-1000 -n 1) | jq ".response[].image.url" | sed $(shuf -i 1-20 -n 1)'!d') &&
wget "$url"

当我运行脚本时,最终wget命令失败并显示以下错误:

"http://a.desktopprassets.com/wallpapers/...jpg": Scheme missing.

当我将URL直接放入wget命令时,如下所示:

wget "http://a.desktopprassets.com/wallpapers/...jpg"

...该命令正确执行并下载图像,这意味着由于变量中的某些问题而发生了错误。

我认为这可能与jq我用来解析Desktoprr API的JSON响应的库有关。

Answers:


22

您需要删除网址周围的双引号,例如,通过使用-r选项jq

url=$(curl 'https://api.desktoppr.co/1/wallpapers?page='$(shuf -i 1-1000 -n 1) | jq -r ".response[].image.url" | sed $(shuf -i 1-20 -n 1)'!d')

当前,该命令实际导致

wget "\"http://a.desktopprassets.com/wallpapers/...jpg\""

太棒了 这个问题让我猛击了键盘。谢谢!
侯赛因·哈利勒
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.