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 2.0k times
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>.shand enter your password to confirm
- Alternatively, you can right-click the .sh file from the file browser and update permissions via the
Propertiesoption
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-editorand hit Enter. - In
dconf-editorgoto:org➤gnome➤nautilus➤preferences - Click on
executable-text-activationand 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
- 5
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,740
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
- 37,804