Open the file explorer Files. Press Alt+F10 and select Preferences. You should see something like this.
In the Behavior tab, select Ask each time and close it. Now double on a shell script will ask you what to do each time. If you want to straight away execute the script, select the first option Run executable text files when they are opened.
This is happen because cron uses only a very restricted set of environment variables. The only one environment variable that is responsible for running in the right way the script from the question when this is set as a cron job is DBUS_SESSION_BUS_ADDRESS.
So, you must to export DBUS_SESSION_BUS_ADDRESS environment variable in your script. See more explanations in my answer here.
In the end, your script should look like:
export DBUS_SESSION_BUS_ADDRESS=$(grep -z DBUS_SESSION_BUS_ADDRESS /proc/$PID/environ|cut -d= -f2-)
if [ -f counter ]
for (( i=$countervar; c<=2000000; i++ ))
echo $i > "counter"
if [ ! -f wallpaper-$i.jpg ]
if [ -f wallpaper-$i.jpg ]
gsettings set org.gnome.desktop.background picture-uri "file:///home/guinness/.rwallpaper/wallpaper-$i.jpg"