Shell script does not run when I double click

9,505

Solution 1

Sounds like your script lacks a shebang line. Make sure the very first line of the script reads:

#!/usr/bin/env bash

or

#!/bin/bash

On a side note, you should avoid putting .sh extension on a bash script, since bash is not sh. Preferably use no extension at all.

Solution 2

This sounds like a known, existing bug: lubuntu-default-settings does not specify the proper command to execute in terminal

That bug report suggests the following workaround (using X-terminal instead.)

WORKAROUND:

In pcmanfm preferences, under the advanced tab, change the terminal to "x-terminal-emulator -e %s". You can also change the "terminal" value in ~/.config/libfm/libfm.conf.

An alternative workaround I've used before is creating a desktop shortcut - but then you're limited to only being able to double-click on the desktop.

To create a shortcut, you can run the command:

lxshortcut -o ~/Desktop/test.sh

(Where test.sh is the name you want the file to have on the desktop.)

This will open lxshortcut, which will create a .desktop file from your responses in a GUI.

Manually creating a .desktop file should also work.

Share:
9,505

Related videos on Youtube

JohnDoe
Author by

JohnDoe

Updated on September 18, 2022

Comments

  • JohnDoe
    JohnDoe over 1 year

    I have made a shell script (test.sh) on my Lubuntu (15.04) desktop. Permissions are: Only owner (View content + Change content + Execute).

    When I double click test.sh, I choose "Execute in Terminal". The Terminal (LXTerminal) opens, but the script is not executed.

    When I type ./test.sh the script is executed. But that is not what I want. Solution for this problem?

  • Tim
    Tim almost 9 years
    +1. I disagree about the .sh part, but the rest seems right.
  • geirha
    geirha almost 9 years
    @Tim, .sh suggests it is an sh script, which is misleading since it's a bash script. Also see talisman.org/~erlkonig/documents/…
  • Tim
    Tim almost 9 years
    Does that apply to .js, .php, .html as well or really just bash files?
  • geirha
    geirha almost 9 years
    @tim, yes if they are commands (that have shebangs and are meant to be executed). So .html does not apply.
  • drkokandy
    drkokandy almost 9 years
    If the script successfully executes when ./test.sh is executed from the terminal, wouldn't it already have to have a shebang line?
  • geirha
    geirha almost 9 years
    @drkokandy. bash is being "helpful" and decides to execute it with bash if execve(2) fails. When running it directly with a terminal, there's no "helpful shell".
  • Deepak Verma
    Deepak Verma almost 9 years
    If using .sh implies it's an sh script, then why wouldn't people use .bash for a bash script? .sh means it's a shell script, and bash is a shell. I think using .sh is just a matter of preference, and a very good case can be made for using it, if desired.
  • geirha
    geirha almost 9 years
    @MartyFried, for a bash script meant to be sourced, adding .bash extension is a good idea. For commands, it's useless information. Most users don't care what language a command is written in as long as it does what it's supposed to do. If users did care, you'd be running ls.elf64 rather than ls to list the files of a directory. I know crappy tutorials, guides and scripts around the net use .sh extensions on bash scripts. That doesn't mean it's a good idea.
  • ancajic
    ancajic over 8 years
    my .sh file starts with #!/bin/bash but double click still doesn't work. And that is the proper path to the bash shell.