18

I wrote a little script that grabs a random wallpaper from the Desktoppr API and changes my desktop wallpaper to it:

#!/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"

When I run the script, the final wget command fails with the error:

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

When I put the URL directly into the wget command, like so:

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

... the command executes correctly and downloads the image, meaning that the error occurs because of some problem in the variable.

I think this might have something to do with the jq library that I am using to parse the JSON response from the Desktoprr API.

2 Answers 2

35

You need to remove the double quotes surrounding the URL, for example by using the -r option to 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')

Currently the command actually results in

wget "\"http://a.desktopprassets.com/wallpapers/...jpg\""
1
  • 1
    Bravo. This problem had me slamming the keyboard. Thanks! Apr 16, 2016 at 17:17
0

I had a similar problem like this.

This return the Scheme Missing Error:

resources=$(cat complete_list_of_urls.txt)
for resource in ${resources[@]};
do
    wget --no-check-certificate https://cyberican.com/images/images/$resource
done

By removing the (") quotation marks, I could extract the data.

resources=$(cat complete_list_of_urls.txt | tr -d '\"')
for resource in ${resources[@]};
do
    wget --no-check-certificate https://cyberican.com/images/images/$resource
done

I hope this help anyone having the same problem :-)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .