bash 如何通过双击在 Linux 上运行脚本
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/42044798/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I run a script on Linux just by double clicking it
提问by pnkjmndhl
I have a script written (which are basically the commands for the terminal for Ubuntu) on a file. Yes, the code starts with
我在文件上编写了一个脚本(基本上是 Ubuntu 终端的命令)。是的,代码以
#!/bin/bash
How do I run this script just by double clicking it? It can be run using the terminal but I want to make it more accessible through my desktop.
如何仅通过双击运行此脚本?它可以使用终端运行,但我想让它更容易通过我的桌面访问。
I was just trying to mimic a *.bat file on windows. A *.bat file on windows contains series of scripts operable on command prompt and executable just by double clicking on it.
我只是想在 Windows 上模仿 *.bat 文件。Windows 上的 *.bat 文件包含一系列可在命令提示符下运行的脚本,只需双击即可执行。
回答by orvi
Follow these steps:
按着这些次序:
Hit
Alt+F2
, typedconf-editor
and hit ``Enter.In dconfg-editor goto:
org ? gnome ? nautilus ? preferences
Click on
executable-text-activation
and from drop down menu select:
点击
Alt+F2
,输入dconf-editor
并点击“Enter”。在 dconfg-editor 中转到:
org ? gnome ? nautilus ? preferences
单击
executable-text-activation
并从下拉菜单中选择:
launch: to launch scripts as programs.
启动:将脚本作为程序启动。
OR
或者
ask: to ask what to do via a dialog.
询问:通过对话框询问要做什么。
Close dconf-editor
Thats it!
关闭dconf-editor
就是这样!
回答by Amr Lotfy
Source https://askubuntu.com/a/286651/113065
来源https://askubuntu.com/a/286651/113065
Edit -> preferences -> Behavior -> Executable Text Files = Run ...
编辑 -> 首选项 -> 行为 -> 可执行文本文件 = 运行 ...
It should run, but you can't see output.
它应该运行,但你看不到输出。
回答by John Montgomery
You need to make it an executable file, either use chmod +x <filename>
or go into the file properties and set it there.
您需要使其成为可执行文件,使用chmod +x <filename>
或进入文件属性并将其设置在那里。