2

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.

wjandrea
  • 14,236
  • 4
  • 48
  • 98
TDSkitz
  • 29

3 Answers3

5

First, ensure your script begins with the correct hash-bang, e.g. #!/bin/bash

Then make sure the .sh file is executable -

  1. Open a terminal using Ctrl+Alt+T or from the applications menu
  2. Navigate to the location of the .sh file. e.g. cd ~/location/to/my/file
  3. Run
    1. chmod u+x <file name>.sh, or
    2. if permission is an issue, sudo chmod u+x <file name>.sh and enter your password to confirm
  4. 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?

  1. Install dconf-editor because it isn't installed by default.
  2. Hit Alt+F2, type dconf-editor and hit Enter.
  3. In dconf-editor goto: orggnomenautiluspreferences
  4. Click on executable-text-activation and from drop down menu and select:
    1. launch: to launch scripts as programs, OR
    2. ask: to ask what to do via a dialog.
  5. Close dconf-editor.

(Source: How do I run executable scripts in Nautilus? Answer courtesy of Basharat Sial)

R.S
  • 179
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