在Linux中创建可执行文件 [英] Creating executable files in Linux

查看:360
本文介绍了在Linux中创建可执行文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我打算做的一件事是编写(非常简单)Perl脚本,我希望能够运行它们而无需从终端显式调用Perl.我对此表示赞赏,我需要向他们授予执行权限.使用chmod做到这一点很容易,但似乎又是一个稍微费力的额外步骤.我想要的是以下两件事之一:

One thing I plan to be doing is writing (painfully simple) Perl scripts, and I'd like to be able to run them without explicitly calling Perl from the terminal. I appreciate that, to do this, I need to grant them execute permissions. Doing this with chmod is easy enough, but it also seems like a slightly laborious extra step. What I would like is one of two things:

首先,有没有一种方法可以在保存文件时设置执行标志?目前,我正在尝试使用gedit和geany,但如果具有此功能,则愿意切换到功能类似(或更好)的编辑器.

Firstly, is there a way to set the execute flag when saving a file? Currently I'm experimenting with gedit and geany, but would be willing to switch to a similarly- (or better-) featured editor if it had this capability.

是否失败,是否有办法声明在特定目录中创建的所有文件都应具有执行权限?

Failing that, is there a way to declare that all files created in a particular directory should have execute permissions?

据我了解,我的umask设置为022,应该可以,但似乎文件是作为文本文件(具有666个默认权限)创建的,而不是作为可执行文件(具有777个默认权限)创建的.

My umask is set to 022, which should be OK, as far as I understand, but it would appear that the files are created as text files (with 666 default permissions) rather than executable files (with 777 default permissions).

也许我只是在偷懒,但是我认为必须有一种更便利的方法,而不是修改每个人创建的单个脚本.

Perhaps I'm just being lazy, but I figure there must be a more convenient way than chmodding every single script one creates.

推荐答案

使文件可执行:

chmod + x文件

chmod +x file

找到perl的位置:

哪个perl

which perl

这应该返回类似

/bin/perl有时是/usr/local/bin

/bin/perl sometimes /usr/local/bin

然后在脚本的第一行中添加:

Then in the first line of your script add:

#!路径"/perl,其路径来自上方,例如

#!"path"/perl with path from above e.g.

#!/bin/perl

#!/bin/perl

然后您可以执行文件

./文件

./file

PATH可能存在一些问题,因此您可能也希望对其进行更改...

There may be some issues with the PATH, so you may want to change that as well ...

这篇关于在Linux中创建可执行文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆