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

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

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:

  1. #!/bin/sh
  2. cd "$(dirname "$(readlink -fn "$0")")"
  3. 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:

  1. #!/bin/sh
  2. cd "$(dirname "$(readlink -fn "$0")")"
  3. 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 文件:

  1. $ cat path-to-script.desktop
  2. [Desktop Entry]
  3. Type=Application
  4. Terminal=true
  5. Name=Click-Script
  6. Icon=utilities-terminal
  7. Exec=gnome-terminal -e "bash -c './script.sh;$SHELL'"
  8. Categories=Application;
英文:

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

  1. $ cat path-to-script.desktop
  2. [Desktop Entry]
  3. Type=Application
  4. Terminal=true
  5. Name=Click-Script
  6. Icon=utilities-terminal
  7. Exec=gnome-terminal -e "bash -c './script.sh;$SHELL'"
  8. 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:

确定