Your script needs a bit of a makeover.
The two lines following the #Set image url, name and location
line are broken for various reasons (e.g. incorrect grep syntax, incorrect assignment). In addition, your script doesn't double quote filenames which may break your script depending on the circumstances.
To make it work more reliably, I rewrote the core of your script as follows:
#!/bin/bash
fn_basedir=~/Pictures/globewall/
fn_index='.index.html'
fn_image='wallpaper.jpg'
mkdir -p "$fn_basedir"
# Get page index
wget -q "https://clients3.google.com/cast/chromecast/home" -O "${fn_basedir}${fn_index}"
if [ $? -ne 0 ]; then
echo "Failed to get index from google chromecast"
exit 1
fi
# Set image url
image_url=$(grep -oP 'https:\\/\\/lh3(.*?)-mv' "${fn_basedir}${fn_index}" | sed -e 's/\\//g' -e 's/u003d/=/g' | head -1)
# Get image
wget -q "$image_url" -O "${fn_basedir}${fn_image}"
if [ $? -ne 0 ]; then
echo "Failed to get image from www.googleusercontent.com"
exit 1
fi
# Change wallpaper
sleep 1
/usr/bin/gsettings set org.gnome.desktop.background picture-options 'zoom'
/usr/bin/gsettings set org.gnome.desktop.background picture-uri "file://${fn_basedir}${fn_image}"
/usr/bin/gsettings set org.gnome.desktop.screensaver picture-uri "file://${fn_basedir}${fn_image}"
echo "Wallpaper changed to ${fn_image}"
exit 0
Awesome pictures btw!