创建一个在终端中打开并执行命令的.desktop文件

我想知道如何编写.desktop文件的Exec命令来打开一个新终端并在其中执行一个shell脚本。 shell脚本正在运行并且可供所有用户访问。 从终端启动脚本时,一切正常,但在尝试从.desktop文件启动脚本时却没有。

以下是我已尝试过的一些组合:

 Exec=gnome-terminal -x sh -c 'echo hello' Exec=sh -c 'gnome-terminal echo hello' Exec=sh -c 'echo hello' Exec=echo hello 

.desktop终端选项设置为true。

桌面文件的内容应如下(请参阅如何使用文本编辑器创建.desktop文件 ):

 [Desktop Entry] Version=1.0 Name=Test Comment=Test the terminal running a command inside it Exec=gnome-terminal -e "bash -c 'echo hello;$SHELL'" Icon=utilities-terminal Terminal=false Type=Application Categories=Application; 

要么:

 [Desktop Entry] Version=1.0 Name=Test Comment=Test the terminal running a command inside it Exec=bash -c 'echo hello;$SHELL' Icon=utilities-terminal Terminal=true Type=Application Categories=Application; 

在第一种情况下, Terminal字段设置为false (可能与您的预期相反),在第二种情况下设置为true ,但结果在两种情况下都相同。

 !#/bin/bash gnome-terminal -e YOUR_COMMANDS 

制作上述文件。 不要忘记sudo chmod +x filename.sh

我这样做 文本文件的第一行是!#/ bin / bash

文本文件的后续行是命令(shell脚本)。

将文件另存为something.sh

打开文件的属性并启用运行文件作为程序。

现在,当双击文件时,我可以选择运行它。