I'm using Ubuntu 18.04 but my .sh files will not execute they just open up in gedit. I have tried changing what the file opens with but Idk which application to choose from the list.
Asked
Active
Viewed 1.8k times
2
-
If you are referring to executing scripts from the file manager, then see Ubuntu 18.04 executable not executing – steeldriver Jul 05 '18 at 00:56
-
I looked at that and it does not help me that well, I changed the preference to Ask waht to do, but the Shell script still just opens gedit – TDSkitz Jul 05 '18 at 01:12
3 Answers
5
First, ensure your script begins with the correct hash-bang, e.g. #!/bin/bash
Then make sure the .sh file is executable -
- Open a terminal using Ctrl+Alt+T or from the applications menu
- Navigate to the location of the .sh file. e.g.
cd ~/location/to/my/file
- Run
chmod u+x <file name>.sh
, or- if permission is an issue,
sudo chmod u+x <file name>.sh
and enter your password to confirm
- Alternatively, you can right-click the .sh file from the file browser and update permissions via the
Properties
option
To make .sh files executable from nautilus(file browser) follow these steps:
Referring - How to execute a script just by double clicking like .EXE files in Windows?
- Install dconf-editor because it isn't installed by default.
- Hit Alt+F2, type
dconf-editor
and hit Enter. - In
dconf-editor
goto:org
➤gnome
➤nautilus
➤preferences
- Click on
executable-text-activation
and from drop down menu and select:- launch: to launch scripts as programs, OR
- ask: to ask what to do via a dialog.
- Close
dconf-editor
.
(Source: How do I run executable scripts in Nautilus? Answer courtesy of Basharat Sial)

R.S
- 179
-
1I think that in point 3 should be "dconf-editor" instead of "dconf-editor" :) – Patryk Godowski Jun 03 '19 at 08:47
2
Check the permissions for the file:
ls -l FILENAME
If the first 4 characters of output aren't -rwx
then change the permissions on the file:
chmod 744 FILENAME

jordy
- 1,670
0
Make sure your .sh
files are marked as executable (have "executable" permission). This is the primary way that a lot of software uses to tell if a file is an executable you want to run or a document you want to open.

thomasrutter
- 36,774