How to launch shell script with double click in CentOS 7

To run your script by double clicking on its icon, you will need to create a .desktop file for it:

[Desktop Entry]
Name=My script
Comment=Test hello world script
Exec=/home/user/yourscript.sh
Icon=/home/user/youricon.png
Terminal=false
Type=Application

Save the above as a file on your Desktop with a .desktop extension. Change /home/user/yourscript.sh and /home/user/youricon.gif to the paths of your script and whichever icon you want it to have respectively and then you'll be able to launch by double clicking it.


Its actually very simple to do that. Just go to your Nautilus files preferences and click on 'Behavior' tab. Under the 'Executable Text Files' check 'Ask each time' or 'Run executable text files when they are opened'. Please look at the screenshot for reference.

Files Preferences


This involves using dconf-editor (sudo yum install dconf-editor):

Open dconf-editor, and navigate to the /org/gnome/nautilus/preferences menu.

Under "executable-text-activation", change "Use default value" to OFF, and "Custom value" to 'launch'.

You can then exit dconf-editor.

At this point, double-clicking on an icon which is a script, or a symbolic link to a script, will execute it, rather than opening up the file with gedit, which is what my system was doing.

So after changing the above preference, all I had to do is:

$ cd $HOME/Desktop

$ ln -s $HOME/bin/myscript.sh MyScript

and that's that.

(My system is GNOME Version 3.1.2 running on CentOs 7)