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:
#!/bin/bash
PID=$(pgrep gnome-session)
export DBUS_SESSION_BUS_ADDRESS=$(grep -z DBUS_SESSION_BUS_ADDRESS /proc/$PID/environ|cut -d= -f2-)
countervar=1;
finish=0;
cd /home/guinness/.rwallpaper/
if [ -f counter ]
then
countervar=`cat counter`
fi
for (( i=$countervar; c<=2000000; i++ ))
do
echo $i > "counter"
if [ ! -f wallpaper-$i.jpg ]
then
wget "http://wallpapers.wallbase.cc/rozne/wallpaper-$i.jpg"
if [ -f wallpaper-$i.jpg ]
then
gsettings set org.gnome.desktop.background picture-uri "file:///home/guinness/.rwallpaper/wallpaper-$i.jpg"
exit
fi
fi
done
Best Answer
Depending on what you are wanting, just add a & to the end of the command
If you are running it in a terminal, and you want to then close the terminal, use nohup or disown
nohup
disown
If that is not what you are after, please be more specific in your question.