2

I want to make a button on my lxpanel to launch a program that prints out Hello World! in a pop-up lxterminal, so I use the technique that I successfully implemented before in Debian 7, which is:

  1. gedit /bin/hello.sh (contents below):

    #!/bin/bash
    echo 'Hello World!';
    
  2. gedit /usr/share/applications/hello1.desktop (below):

    [Desktop Entry]
    Version=1.0
    Type=Application
    Name=Hello1
    Comment=Test the terminal running a command inside it
    Exec=lxterminal -e "/bin/hello.sh"
    StartupNotify=true
    Icon=utilities-terminal
    Terminal=true
    Categories=Utility;
    
  3. Last I chown and chmod both of the above files as below:

    -rwxr-xr-x 1 a adm 230  1月  1 13:02 /usr/share/applications/hello1.desktop*
    -rwxr-xr-x 1 a adm 240  1月  1 12:57 /usr/share/applications/hello1.desktop~*
    -rwxr-xr-x 1 a adm 194  1月  1 12:04 /usr/share/applications/hello.desktop*
    -rwxr-xr-x 1 a adm 195  1月  1 12:03 /usr/share/applications/hello.desktop~*
    -rwxrwxr-x 1 a adm  87  1月  1 12:35 /usr/share/applications//bin/hello.sh*
    -rwxrwxr-x 1 a a    87  1月  1    12:25 /usr/share/applications//bin/hello.sh~*
    -rwxrwxr-x 1 a adm 134 12月 13 09:56 /usr/share/applications//bin/hello_world.sh*
    

Unfortunately no matter what I do, the hello1.desktop file only can open a blank lxterminal, and there is no output.

I am running Lubuntu 14.04 and have followed the following tutorials to link a desktop file to a *.sh script program:

I also made the following variations to hello1.desktop:

  • line 10 (last line) - I also tried it without a semi-colon.
  • line 9 (the "Terminal" line) - tried "false"
  • line 6 (the "Exec" line) - tried these:

    Exec=sh /bin/hello.sh;
    Exec=lxterminal -e “/bin/hello.sh”
    Exec=/bin/hello.sh
    Exec=sh -c /bin/hello.sh
    Exec=lxterminal -x sh -c 'echo hello'
    Exec=sh -c 'gnome-terminal echo hello'
    Exec=sh -c 'echo hello'
    Exec=sh /bin/hello.sh
    Exec=sh -c /bin/hello.sh
    

But in the end all are the same (except when Terminal=false on line 9 there is no terminal, obviously).

I can see hello1 under System -> Accessories, but when I click on it still just a blank screen pops out. In debian 7.5 LXDE wheezy this is really easy to do successfully, but what is wrong in Lubuntu 14.04 to make it so much more difficult?

Andrew

wjandrea
  • 14,236
  • 4
  • 48
  • 98
afc888ny
  • 103
  • 2
  • 7
  • 3
    Skip the HTML tags and format it as code (select and press press Ctrl-K). At the moment it is hard to say what's in your files and what's not. – muru Jan 01 '15 at 10:43
  • @muru I fixed it. Hopefully I didn't break anything. – wjandrea Feb 12 '19 at 20:21
  • How did you get that ls output? Why are there files like /usr/share/applications//bin/hello.sh? Why are you adding system-level files to test this instead of user-level (i.e. in ~/bin and ~/.local/share/applications). How are you using gedit without sudo to edit system-level files? Also note you have curly quotes in one of those exec lines: Exec=lxterminal -e “/bin/hello.sh” (I know this is an old question - just voicing my concerns in case of similar questions in the future.) – wjandrea Feb 12 '19 at 20:35

1 Answers1

2

I have managed to duplicate your problem and have a solution.

As your research has told you, your original problem was having:

Terminal=true

together with:

Exec=lxterminal -e /bin/hello.sh

The only problem is, that when you use:

Terminal=false

the terminal closes after executing the script, though it does actually run your script. As your script produces so little output it is not humanly possible to see this taking place so it seems like a "blank screen popping out".

As far as I can see (from man lxterminal and from Google), there is no specific way to ask lxterminal to stay open after it has executed a script, so you have to change the bash script (i.e. your hello.sh) itself.

For example you could add either of the following to the end of your script.

  1. echo "Press [ENTER] to exit" && read

    • The terminal will wait for the user to hit Enter. (In fact to type anything followed by Enter.)
  2. /bin/bash

    • The terminal will stay open.

For a discussion of the general problem of stopping the shell from closing after executing a command, including information about other terminal emulators, see: How to run a script without closing the terminal?

By the way the semicolon at the end of the Desktop file doesn't do anything, so you might as well remove it.

Summary: The only change you need to make to your original desktop file is Terminal=false, but you need to add a line to the end of your bash script if you want to see that the script has run.

wjandrea
  • 14,236
  • 4
  • 48
  • 98
  • Harlinski,    Thanks for your help, but when I try the first solution:
    1. change hello.desktop file's contents from 'Terminal=true' to 'Terminal=false'
    2. change 'hello.sh' contents

    FROM:

    #!/bin/bash

    echo 'Hello World!'

    TO:

    #!/bin/bash echo 'Hello World!' echo "Press [ENTER] to exit" && read

    OR TO:

    #!/bin/bash echo 'Hello World!' /bin/bash

    1. I removed the semi-colon at the end of my desktop file.
    2. openbox –reconfigure
    3. Press the button “hello” on the lxpanel

    Unfortunately, ...

    – afc888ny Jan 05 '15 at 02:36
  • (con't.)...Still now, like from the start, there is merely a new blank lxterminal that pops up and just sits there without any 'Hello World!' output. – afc888ny Jan 05 '15 at 02:41
  • I'm away from my Lubuntu box for a couple of weeks so can't directly help. All I can recommend is you strip down levels of complexity until you find the problem. So start with a user-owned desktop file on the Desktop calling a user-owned script, working up to your final configuration. – harlandski Jan 05 '15 at 04:38
  • solved on [link]http://www.linuxquestions.org/questions/showthread.php?p=5296849#post5296849[link] – afc888ny Jan 07 '15 at 08:56