Linux 哪种脚本语言最好?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/70453/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-03 16:25:35  来源:igfitidea点击:

Which Scripting language is best?

linuxscripting

提问by Sreenath

For writing scripts for process automisation in Linux platform, which scripting language will be better? Shell script, Perl or Python or is there anything else? I am new to all of them. So, am just thinking to which one to go for?

在 Linux 平台上为流程自动化编写脚本,哪种脚本语言会更好?Shell 脚本、Perl 或 Python 还是其他什么?我对他们都很陌生。所以,只是想着去哪一个?

采纳答案by Simon Peverett

The answer is: Whatever best fits the job!

答案是:什么最适合这份工作!

My rule of thumb;

我的经验法则;

Bash- for a short script that might need a for loop to do something repetitively.

Bash- 对于可能需要 for 循环来重复执行某些操作的简短脚本。

Perl- anything to do with some kind of text processing or file processing, especially if it's a one off. Just do a dirty nasty perl script and be done with it

Perl- 与某种文本处理或文件处理有关的任何事情,特别是如果它是一次性的。只需做一个肮脏讨厌的 perl 脚本并完成它

Python- If it's something you might want to do again or something very like it. Then at least you have a chance of being able to reuse the script.

Python- 如果它是您可能想要再次做的事情或非常喜欢的事情。那么至少您有机会重用该脚本。

回答by Vargen

I have been getting Python recommended all the time. It's supposed to let you do anything. For the small tasks i use shell scripts though.

我一直都在推荐 Python。它应该让你做任何事情。不过,对于小任务,我使用 shell 脚本。

回答by Bernard

On Linux? Choose your poison, basically. I like Python, others Ruby, still others Perl. Pick one and go for it. :-)

在 Linux 上?基本上选择你的毒药。我喜欢 Python,其他人喜欢 Ruby,还有人喜欢 Perl。选择一个就可以了。:-)

回答by Ben

I think it depends on how complex the tasks are you want to automate. Personally, I've always gone with shell-scripts, which enables you to call on awk, sed, grep, find, ls, cat, etc. which can be combined together to do pretty much anything you can achieve using perl or python. On the other hand, if the processes you want to automate are complex (e.g., not just a linear sequence of steps) then you'll probably find that writing the scripts in perl or python (or even ruby!) is much quicker and makes them easier to maintain.

我认为这取决于您想要自动化的任务有多复杂。就我个人而言,我一直使用 shell 脚本,它使您能够调用 awk、sed、grep、find、ls、cat 等,它们可以组合在一起完成几乎可以使用 perl 或 python 实现的任何事情。另一方面,如果您想要自动化的过程很复杂(例如,不仅仅是步骤的线性序列),那么您可能会发现用 perl 或 python(甚至 ruby​​!)编写脚本要快得多,并且它们更易于维护。

回答by Xetius

I would usually say the one you know best which can achieve the results you want. Like all religious wars, and after learning a large number of languages, you realise that you can do most things in most languages (Note I did say most). I use Perl. It is maybe not as up to date as Python or Ruby, but it does have massive library support from CPAN. And I have not found anything I can't do in it yet. When I do I will look at other languages to find out which one can fill that gap.

我通常会说你最了解的那个可以达到你想要的结果。像所有宗教战争一样,在学习了大量语言后,您会意识到您可以用大多数语言做大多数事情(注意我说的最多)。我使用 Perl。它可能不像 Python 或 Ruby 那样最新,但它确实有来自 CPAN 的大量库支持。而且我还没有发现任何我不能做的事情。当我这样做时,我会查看其他语言,以找出哪种语言可以填补这一空白。

If I was starting today, maybe I would pick Python or Ruby, but I don't know enough about them to make a judgement call. Do any of your friends/colleagues know scripting languages. This could help you massively as the support when learning a new language is very important.

如果我从今天开始,也许我会选择 Python 或 Ruby,但我对它们的了解不够,无法做出判断。您的朋友/同事是否知道脚本语言。这可以为您提供大量帮助,因为在学习新语言时的支持非常重要。

Good luck

祝你好运

回答by GustyWind

That depends on which type of automation you are doing like if it is testing autoamtion Perl is suggested because Perl is much powerful extension modules via CPAN, an online Perl module inventory. If you only need a handy tool to complete a simple source file, awk is very convenient. If you are planning to use the scripts to automate a big project, Perl is a better choice with more features. Again Python was designed from the start as an object-oriented language. Perl 5 has some o-o features added on, but it looks to me like an awkward retrofit. Python has well-implemented o-o features for multiple inheritance, polymorphism, and encapsulation.n summary, it seems to me that Python dominates Perl in most applications except for fairly short shell-script sorts of applications, and there they are roughly comparable.

这取决于您正在执行哪种类型的自动化,如果它正在测试 autoamtion 建议使用 Perl,因为 Perl 是非常强大的扩展模块,通过 CPAN,一个在线 Perl 模块清单。如果你只需要一个方便的工具来完成一个简单的源文件,awk 是非常方便的。如果您打算使用脚本来自动化一个大型项目,Perl 是一个更好的选择,它具有更多功能。Python 从一开始就被设计为面向对象的语言。Perl 5 添加了一些 oo 功能,但在我看来它像是一个笨拙的改造。Python 在多重继承、多态和封装方面具有良好实现的 oo 特性。总而言之,在我看来,除了相当短的 shell-script 类型的应用程序外,Python 在大多数应用程序中都在 Perl 中占主导地位,并且它们大致可比。

回答by Vinko Vrsalovic

Go for all three of them, start with bash/awk/sed plus fileutils (grep, find, and so on) and then move up the abstraction hierarchy with perl and python.

选择所有三个,从 bash/awk/sed 和 fileutils(grep、find 等)开始,然后使用 perl 和 python 向上移动抽象层次结构。

That way you will be able to decide for yourself which one fits your needs best. I say start with bash and friends because they are ubiquitous, some machines will not have perl or python installed and you'll feel helpless there, especially in traditional unix land (ie, not linux)

这样您就可以自己决定哪一种最适合您的需求。我说从 bash 和朋友开始,因为它们无处不在,有些机器不会安装 perl 或 python,你会在那里感到无助,尤其是在传统的 unix 领域(即不是 linux)

回答by ctcherry

Depends on the complexity and problem domain of the task at hand.

取决于手头任务的复杂性和问题域。

Bash scripts are quick and dirty for simple system automation tasks. For more complex things than moving files around and running commands, I'd personally say Perl is next in line as the defactosys-admin goto automation tool. For more focus on code reuse and readability/maintainability I'd want to step it up it up to Python or Ruby.

Bash 脚本对于简单的系统自动化任务来说既快速又脏。对于比移动文件和运行命令更复杂的事情,我个人认为 Perl 是事实上的sys-admin goto 自动化工具。为了更多地关注代码重用和可读性/可维护性,我想将其升级为 Python 或 Ruby。

PHP can also be used to automate tasks, however it is not widely accepted for this purpose in my experience.

PHP 也可用于自动执行任务,但根据我的经验,它并未被广泛用于此目的。

It really comes down to what language you are most interested in learning, most can be used for automation, in addition to many other things.

这真的归结为您对学习最感兴趣的语言,除了许多其他东西之外,大多数可以用于自动化。

回答by Vhaerun

Well, it's like this:

嗯,是这样的:

Perl is not the most user friendly scripting language, but it has CPAN (Comprehensive Perl Archive Network), which contains thousands of libraries that implement almost anything you may think of, and Perl is really powerful when it comes to text processing. The disadvantage would be that perl code is kinda hard to maintain (if you don't know it very well).

Perl 不是对用户最友好的脚本语言,但它具有 CPAN(综合 Perl 档案网络),其中包含数千个实现您可能想到的几乎任何东西的库,而且 Perl 在文本处理方面非常强大。缺点是 perl 代码有点难以维护(如果你不太了解的话)。

Python is a scripting language that is becoming more and more popular among scripters. It doesn't have a community like CPAN (yet), but it's more readable, and it's easier to maintain. It's as fast as perl.

Python 是一种脚本语言,在脚本编写者中越来越流行。它没有像 CPAN(还)这样的社区,但它更具可读性,并且更易于维护。它和 perl 一样快。

Ruby is the newest trend in scripting languages. Ruby is full OOP, which means that everything is an object. Its advantage is that the code is very readable, and it's pretty easy to learn, if you are a beginner. The main disadvantage is its execution speed, which kinda s*x.

Ruby 是脚本语言的最新趋势。Ruby 是完全面向对象的,这意味着一切都是对象。它的优点是代码可读性很强,如果您是初学者,也很容易学习。主要的缺点是它的执行速度,有点 s*x。