3

I'm using Ubuntu and I've created a simple script file:

#!/bin/bash
cp /home/guilherme/pictures/*.jpg /home/guilherme/backup

When I run it on terminal typing the command "./script.sh" it works fine.

But when I try to click on this file outside the terminal, it opens my text editor to edit the lines of the script instead of opening the terminal and execute the commands.

I already gave the executable permission to this file, but it does not run.

Any ideas?

4
  • Have you tried removing the .sh extension? Maybe Nautilus (or whatever file browser you're using) checks that.
    – tjameson
    Jul 13, 2013 at 1:59
  • yeah, I removed the extension and nothing happens
    – user2576376
    Jul 13, 2013 at 2:02
  • please send us ls -la of the script. check that the mountpoint is not mounted noexec.
    – mnagel
    Jul 13, 2013 at 2:52
  • This is surely not a programming question--please ask on SuperUser instead.
    – John Zwinck
    Jul 13, 2013 at 4:17

5 Answers 5

7

You have to open nautilus, click File->Preferences (OR) Edit->Preferences, check Behaviour tab, and select the option you prefer for Excutable Text Files.

enter image description here

1

On Ubuntu 14.04:

  1. Open Nautilus .
  2. Hit Alt.
  3. Type preferences.
  4. Hit Enter.
  5. Choose Behavior tab. Under Executable Text Files choose Ask each time.

You also need to mark your files as executables. To do that right click the .sh file, choose Properties, and under the Permissions tab check Allow executing file as a program.

0

Go to your system settings -> keyboard -> keyboard shortcuts and add a custom shortcut. For the command place the full path to the script. Now you can run it without terminal

1
  • how if it needs password to run?
    – Ravan
    Jan 10, 2016 at 10:52
0

Because i still see that a lot, for 20.04:

open Files then Preferences

Here

Then Behavior and check "Run them".Now you are able to double click .sh files and run (only if the file.sh is executable,right click in file.sh -> Permissions-> check "Allow executing file as a program").Now all your executables will run.If you dont want that for some scripts.sh,uncheck "Allow executing file as a program" and run it with 'bash yourscript.sh' from terminal.Working fine for me!

-2

in terminal type "chmod +x filepath". This will convert your sh file to an executable file that will run when you open it

1
  • 2
    Your answer is incorrect. It does not change it into a executable. Please delete your answer.
    – fosslinux
    Jun 23, 2016 at 0:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .