Ubuntu 16.04 Nautilus 中的双击 Shell 脚本仅提供用户编辑 shell 脚本文件的选项

Ubuntu 16.04 Nautilus 中的双击 Shell 脚本仅提供用户编辑 shell 脚本文件的选项
When I follow the steps in 

[https://askubuntu.com/questions/138908/how-to-execute-a-script-just-by-double-clicking-like-exe-files-in-windows]

我曾经收到一个对话框,询问我是否要执行 shell 脚本或使用 gedit 编辑它。我刚刚使用 LiveCD 重新安装了 Ubuntu Linux 16.04 并运行了 sudo apt-get install mono-complete。现在,当我在 Ubuntu 16.04 Nautilus 中双击 shell 脚本时,我只能编辑 shell 脚本文件。

The contents of this shell script are:

#!/bin/bash
exec /usr/bin/mono-service.exe ./AudioRecorder.exe  "$@".

as specified in 

  [http://www.mono-project.com/archived/guiderunning_mono_applications/]

为什么会出现这个问题,我们该如何解决它,所以双击 Nautilus 中的 shell 脚本询问我是否要执行 shell 脚本文件?

任何帮助是极大的赞赏。

答案1

首先,/usr/bin/mono-service.exe不存在。

接下来,根据您发布的链接。你的脚本应该是这样的:

#!/bin/sh
/usr/bin/mono /usr/lib/mono/4.5/mono-service.exe ./AudioRecorder.exe  "$@"

或者

#!/bin/sh
/usr/bin/mono-service ./AudioRecorder.exe  "$@"

或者

#!/bin/bash
mono ./AudioRecorder.exe  "$@"

或者

#!/bin/sh
/usr/bin/mono ./AudioRecorder.exe  "$@"

但是,这些仅当 exe 文件位于您的主文件夹中时才有效,并且理想情况下,如果 exe 文件位于您的主文件夹中,则应包含 exe 文件的实际路径,如下所示:

#!/bin/sh
/usr/bin/mono /usr/lib/mono/4.5/mono-service.exe ~/AudioRecorder.exe  "$@"

或者

#!/bin/sh
/usr/bin/mono-service ~/AudioRecorder.exe  "$@"

或者

#!/bin/bash
mono ~/AudioRecorder.exe  "$@"

或者

#!/bin/sh
/usr/bin/mono ~/AudioRecorder.exe  "$@"

或者,如果该文件位于您的“下载”文件夹中:

#!/bin/sh
/usr/bin/mono /usr/lib/mono/4.5/mono-service.exe ~/Downloads/AudioRecorder.exe  "$@"

或者

#!/bin/sh
/usr/bin/mono-service ~/Downloads/AudioRecorder.exe  "$@"

或者

#!/bin/bash
mono ~/Downloads/AudioRecorder.exe  "$@"

或者

#!/bin/sh
/usr/bin/mono ~/Downloads/AudioRecorder.exe  "$@"

答案2

这是我找到的回答问题的网址。

双击 Linux Bash 脚本并使用暂停命令进行调试

@terdon 的回答非常好:

您的脚本需要一个终端才能与其交互。 @Sebastian 建议的一种方法是这样做。但请注意,bash 脚本并不是真正设计为以这种方式运行的。一种更简洁的方法是编写一个启动脚本的 .desktop 文件,然后双击该文件。就像是:

[Desktop Entry]
Exec=/home/user/yourscript.sh
Terminal=true
Type=Application

将该文件作为 foo.desktop 保存在 ~/Desktop 文件夹中。现在它将显示为一个图标,双击它将使您的脚本在终端中运行。显然,您需要将 /home/user/yourscript.sh 更改为脚本的实际路径。

有一个问题仍然悬而未决:使用 @terdon 的模拟器,如何将 stdin、stdout 和 stderr 重定向到 /dev/null?

[编辑于 2016 年 6 月 2 日 上午 4:30 重定向 stdout 和 stderr 的方法是在后台执行 mono-service ./AudioRecorder.exe & ]

相关内容