How to execute a script just by double clicking like .EXE files in Windows?
Solution 1
I tested this and it worked fine. Ensure your script begins with the correct shebang, e.g. #!/usr/bin/env bash
.
Then follow these steps:
- Hit Alt+F2 to run a command.
- Type
dconf-editor
and hit Enter. - In dconfg-editor go to:
org ➤ gnome ➤ nautilus ➤ preferences
-
Click on
executable-text-activation
and from drop down menu select:launch: to launch scripts as programs.
OR
ask: to ask what to do via a dialog. Close dconf-editor. Thats it!
Alternative way, using terminal: Run:
gsettings set org.gnome.nautilus.preferences executable-text-activation 'launch'
Note: The file should be executable. You may also need to change permission of file. Right click and set "Allow executing file as program"
Solution 2
On Nautilus (AKA Files)
-
Go to Files (Edit on Unity (17.04 or below)) > Preferences > Behavior tab
-
Change the settings for executable text file.
Solution 3
I think creating a *.desktop file is missing here:
$ cat shortcut-for-my-script.desktop
[Desktop Entry]
Type=Application
Terminal=true
Name=Click-Script
Icon=utilities-terminal
Exec=gnome-terminal -e "bash -c './script.sh;$SHELL'"
Categories=Application;
If you create more than one *.desktop file for one script you are able to create multiple configurations by passing different parameters, which is a very comfortable and user-friendly way.
Solution 4
In Ubuntu and all Unix based OSes, afaik, nothing is set as executable by default. There are two ways of doing this.
Right click on the script or file you want to execute. Go to Properties then to the Permissions Tab. Click the check box that says Execute.
Open a Terminal
cd
into the directory where the file is found. Typechmod ugo+x filename
. This will set the file to execute.
Now your users can double click to their hearts content.
Solution 5
For Ubuntu 20.04:
- Open Files (Nautilus is called Files now), click on the hamburger menu and select Preferences.
- Go to the Behaviour tab and select what's suitable from the Executable Text Files section
Related videos on Youtube
Community
Updated on September 18, 2022Comments
-
Community over 1 year
How can I make a bash script executable by double clicking just like
.exe
files in Windows? I tried creating a launcher and assigning the script to it, but there are two consequences:- the terminal twinkles, disappears, and nothing is done.
- you must specify to run in terminal in order to work.
I have a script that installs tomcat on an offline PC, including all dependencies of tomcat in the script. I need to make the script work on double clicking like windows since most who use the script will not be familiar with Ubuntu.
Forget the above explanation. I want to make a script that can be run by double-clicking on it, without using the terminal. Anybody knows how?
-
Admin about 12 yearsI think you may just be writing your desktop file poorly. Can you post (verbatim) the .desktop launcher that you wrote?
-
Admin about 12 yearsAlso, have you seen this? askubuntu.com/q/34597/24694
-
Admin about 12 yearsIts just a launcher where you assign name and command to do its not that big idea
-
Admin over 11 yearsAlso note, that scripts in linux are not called bash but shell afaik.
-
Admin over 8 yearsmuru tipped me off to this, worked for me: askubuntu.com/questions/286621/…
-
Admin over 5 yearsFYI for future visitors: Nautilus, the default file manager on Ubuntu, apparently will be removing the ability to run executables in newer releases in 2019 due to vulnerabilities. Article on the topic and code commit on GitLab with discussion
-
Admin about 12 yearsIt still will ask you what to do with run in terminal or display or run ... So its not what i need
-
Admin about 12 yearsBroth Ali sure i did it its obvious to do that
-
Admin about 12 yearsi did that but what prob is the terminal just twinkles and nothing happens
-
ryanjdillon almost 11 yearsThis worked great. Just a note, the "drop down menu" is reached by clicking on the value listed to the right of
executable-text-activation
(default value isdisplay
). -
whale_steward about 9 yearsfor those who cannot call the app, you need to install it first with
sudo apt-get install dconf-editor
-
shrx about 9 yearsThis works everywhere except on the Desktop. How can I make it work on the Desktop as well? I'm using Xubuntu 14.10.
-
childofsoong about 9 yearsIs there a way to do this in LXDE (for Lubuntu)?
-
raddevus over 8 yearsThis works great under slax unix to -- see slax.org for the really great Unix system you can boot off of a thumb drive.
-
Hendry Tanaka about 8 yearsNice answer!! This answer should be mark as correct right? Haha..
-
Brian Cowan about 8 yearsWorks great on RHEL 7.2 as well... Saved me some digging..
-
jcubic over 7 yearsIs there a way to make this work in XFce?
-
Kunok about 7 yearsOnly this answer worked on Gnome Ubuntu 17.04 for making desktop file executeable
-
niry over 6 yearsNow 'Files -> Preferences'. (17.04)
-
codepleb over 6 yearsSweet! The way to go imho.
-
Sean Bone over 6 yearsMajor issue: *.cpp files also seem to attempt to execute, however that of course does nothing. It's quite a pain.
-
bad_keypoints about 6 yearsAlt+F2 is supposed to launch the terminal right? Wasted a few minutes there, trying to launch dconf-editor in tty of Ctrl+Alt+F2, as Alt+F2 did nothing in my system. Just had to launch the terminal, launch dconf-editor there. Worked.
-
Amr Lotfy over 5 yearsHow to see output ?
-
BuvinJ about 5 yearsThis the best answer for Ubuntu. Note that you may not (or probably do not?) need to specify
Terminal=True
andExec=gnome-terminal
unless you are literally creating a shortcut for a script that you want to see the output of within a terminal window... Also note that you can pointIcon
to whatever custom png you might want... -
DimiDak about 5 yearsThis is for executing file on terminal, not by double clicking it.
-
cipricus over 4 yearsHere on how to achieve the purpose with custom actions in Thunar (without re-enabling that "risky" feature).
-
cipricus over 4 yearsAlso here on how to use Zenity and get a question "Edit or Run?"
-
Mr-Programs over 4 yearsget this as untrusted tho
-
muyustan about 4 yearsThis method does not allow you to be able to launch by double clicking.
-
gog over 2 yearsI was launching a script that launches other applications, and them crashed after a couple of seconds, being hit by SIGHUP. Using
bash -c "./script.sh; $SHELL"
like stated here solved the problem. Great!