linuxbashshdouble-click

How to run a .sh script in terminal by double-clicking?


I have a .sh script that I would like to run in a terminal window upon being double-clicked. This is the contents of the script:

#!/bin/sh
cd "$(dirname "$(readlink -fn "$0")")"
java -Xmx1024M -Xms1024M -jar minecraft_server.1.19.jar nogui

Is there any way to modify the script so that the output could be displayed back to the user?

I have looked online for any potential solutions, and the closest I have found is this article, which takes advantage of options that are not provided to me by my distro (Kubuntu). I have also attempted to set the file to, by default, open with a terminal, however the script does not run.


Solution

  • I think one solution is crating a *.desktop file here:

    $ cat path-to-script.desktop   
    [Desktop Entry]
    Type=Application
    Terminal=true
    Name=Click-Script
    Icon=utilities-terminal
    Exec=gnome-terminal -e "bash -c './script.sh;$SHELL'"
    Categories=Application;