4

So I tried making a desktop shortcut which executes a very simple shell script. But when i double click/right click->execute it, it does nothing. (or at least I think it does nothing)

heres how my shortcut and shell script looks: Note the shortcut has "Terminal" set to 1, and i hope that means that it opens the shell script in a new terminal window.. (i have a couple terminals already open, which arent ready for usage (have scripts running))

Shortcut:

[Desktop Entry]
Version=1.0
Type=Application
Name=Test
Comment=Test
Exec=/home/(myusername)/test/test.sh
Icon=utilities-terminal
Terminal=true
StartupNotify=false
GenericName=Test

Shell Script:

#!/bin/sh
# (I tried both, /bin/bash and /bin/sh)
echo "hi"
RolandiXor
  • 51,541

2 Answers2

6

Both the desktop entry and the shell script should have executable permissions. Do:

$ chmod +x path_to_shortcut/shortcut.desktop
$ chmod +x path_to_script/test.sh  

Another way to change permissions for a script is to right click it, go to Properties > Premissions and check Allow executing file as program.

Permissions

ignite
  • 8,936
  • it does not fully work but it does execute now. But is that even the right way? I used the right click, create launcher button.. shouldnt that automatically give my launcher execution permission.. hows that user friendly.. thats also the reason why i didnt give it +x myself, i only gave +x to test.sh – DeadSix17 Feb 19 '13 at 02:03
  • You have to give executable permissions explicitly, see edit to my answer. – ignite Feb 19 '13 at 02:09
  • i told you i did that from the begin (just not on the shortcut).. the problem is that the script doesnt open in a new Terminal, also adding this command opens a terminal though: "/usr/bin/xfce4-terminal" so i thought hm.. probably terminal allows argument 1 to be a shell script .. and i tried that.. but doesnt work. So to make it more easy to understand what i need, i want a Shortcut that opens a NEW! Terminal and runs a specific Shell Script in it. (I did add execution permissions to both, the shortcut and the Script) Also tried running terminal itself and gave it a shell script path as arg – DeadSix17 Feb 19 '13 at 02:24
  • As you have set Terminal=True, your script should have opened in a terminal itself or you want two terminals? – ignite Feb 19 '13 at 02:35
  • No, i want a single terminal to open even if there are already X ammount of terminals open. – DeadSix17 Feb 19 '13 at 02:35
  • It does open a new terminal, irrespective of how many terminals are already open. However you will see it for a very short time, as it executes almost immediately. – ignite Feb 19 '13 at 02:39
0

Just in case someone comes here from google search... In 14.04 it's been a pain in the rear to execute shell script which starts Android Studio for me on the mounted drive. Tried numerous things but nothing worked for me. Eventually had to write below code and compile with:

gcc -o studio studio.c 

and then create a shortcut to "studio" from the desktop and now it finally works as it should.

Here is the sample code, you can replace path (/media/.../studio.sh) in that system call after /bin/sh. Make sure it's a full path and leave "/bin/sh " in front.

#include <stdio.h>
int main(void) {
  int ret = system("/bin/sh /media/jeneag/APPS/linux/android-studio/bin/studio.sh");
  printf("app ret code: %d\n", ret);
  return 0;
}
Jenya G
  • 101
  • While this certainly works, I don't see the point of jumping through all these hoops when marking the script executable and symlinking it to the desktop should do. – David Foerster Oct 21 '14 at 14:18
  • Only if that worked all of the time: -rwxrwxrwx 1 jeneag jeneag 5889 Aug 8 13:39 studio.sh It is executable, but still opens in vim/editor. Not to mention that external/internal mounted HDD unless property defined in /etc/fstab with ntfs-3g exec,users,permissions... lines it will be owned by root:root and chmod +x would not do anything at all. – Jenya G Oct 21 '14 at 15:08
  • 1
    You probably forgot to configure the file browser to run executable files instead of viewing/editing them. – muru Oct 21 '14 at 15:18
  • That and does the shell script start with a shebang (though /bin/sh is the default interpreter for files without one)? – David Foerster Oct 21 '14 at 15:30
  • Yes it starts with #!/bin/sh. As far as configuring, nothing was changed from 12.x ubuntu when I did an upgrade to 14.04 2 days ago. Last couple of releases Ubuntu makes me and my dev friends spend 1+ hours on configurations to get rid of all of that fancy stuff so desktop would be useful for software development. – Jenya G Oct 21 '14 at 15:32