如何通过双击在终端中运行一个.sh脚本?

huangapple go评论65阅读模式
英文:

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.

英文:

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.

答案1

得分: 0

我认为一种解决方案是在这里创建一个 *.desktop 文件:

$ 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;
英文:

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;

huangapple
  • 本文由 发表于 2023年5月8日 01:46:50
  • 转载请务必保留本文链接:https://go.coder-hub.com/76195415.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定