4

I recently migrated from fedora 10 to Ubuntu 14.04 and believe me it was a real challenge :)

I almost managed to work anything out but only one problem is remaining. in fedora 10 i used to create .sh file containing commands to be executed in terminal and easily run those by double clicking on .sh file.

here is the method i was using in fedora:
1- creating a file with gedit
2-typing the command in it
3- chmod u+rwx example.sh

I followed the same method in Ubuntu but it does not work. however the shell file works perfectly when I type sh example.sh . also I read somewhere to go and allow the file to be executable and choose terminal as a default program for shell script file type, but there is no terminal in that list.

Sergiy Kolodyazhnyy
  • 105,154
  • 20
  • 279
  • 497

2 Answers2

9

There's a simple method to make executable on Ubuntu; I've done so and it's worked fine.

You can either use the graphical method, by opening the properties dialog of the script, selecting permissions and Allow executing files as program.

Or you can run chmod +x yourscript.sh.

First though, make sure your file manager supports executing files:

gsettings set org.gnome.nautilus.preferences executable-text-activation ask
TellMeWhy
  • 17,484
3

You doing everything correctly, but there's one more extra step - you need to tell the default file manager to allow running executable files.

Open the file manager and go to Edit -> Preferences -> Behavior. Check "Run executable files when they are opened" (it's under Executable Text Files).

Once you do that, you will be able to run those. Remember however, that if you actually want to see them run in terminal, you need to specify that in the script itself. For instance,

#!/bin/sh
gnome-terminal -e 'mc' &
Sergiy Kolodyazhnyy
  • 105,154
  • 20
  • 279
  • 497
  • 1
    My answer was better :P ;) http://askubuntu.com/a/661884/367165 – A.B. Sep 01 '15 at 13:53
  • Yes, I like the gsettings way . I didn't know there's schema for it ^_^ – Sergiy Kolodyazhnyy Sep 01 '15 at 14:17
  • can you explain this more? ""if you actually want to see them run in terminal, you need to specify that in the script itself""? my problem is solved now and when i double click on the .sh file it ask to run in terminal and etc but when i choose terminal it can not find the program (ns2). – user329907 Sep 01 '15 at 16:52
  • @user329907 so , if you don't tell your script to output to the terminal, like I did in my answer up above, it will run in the background, doing stuff,but not showing up. As for your script: what do you mean you cannot find the program ? what exactly happens ? can you explain in more detail ? – Sergiy Kolodyazhnyy Sep 01 '15 at 17:02
  • @serg it says ns : not found – user329907 Sep 01 '15 at 17:04
  • @Serg my script is look like this now : "ns script.tcl sleep 100 " do you mean i need to change it to "#!/bin/sh gnome-terminal -e 'ns script.tcl' &" because i've tried it and it does not work. – user329907 Sep 01 '15 at 17:15
  • OK, so two things. First, make sure ns is installed. Second,make sure the path to ns is in your $PATH variable. Check it with echo $PATH and which ns . Also, sleep command should be separated with ; unless it's one of the arguments to ns command. So ns script.tcl; sleep 100 – Sergiy Kolodyazhnyy Sep 01 '15 at 17:31
  • as much as i know path variables are fine but i am not sure if i need to give a command like ns some permissions or something to be able to called by a shell script. – user329907 Sep 01 '15 at 18:14