mirror of
https://github.com/LCTT/TranslateProject.git
synced 2024-12-26 21:30:55 +08:00
翻译完成
This commit is contained in:
parent
027f789962
commit
54bec3d3c7
@ -1,68 +0,0 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (geekpi)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (Bash vs. Python: Which language should you use?)
|
||||
[#]: via: (https://opensource.com/article/19/4/bash-vs-python)
|
||||
[#]: author: (Archit Modi (Red Hat) https://opensource.com/users/architmodi/users/greg-p/users/oz123)
|
||||
|
||||
Bash vs. Python: Which language should you use?
|
||||
======
|
||||
Both programming languages have pros and cons that make them better for
|
||||
some tasks than others.
|
||||
![][1]
|
||||
|
||||
[Bash][2] and [Python][3] are most automation engineers' favorite programming languages. Both have pros and cons, and sometimes it can be hard to choose which one you should use. The honest answer is: It depends on the task, the scope, the context, and the complexity of the task.
|
||||
|
||||
Let's compare these two languages to get a better understanding of where each one shines.
|
||||
|
||||
### Bash
|
||||
|
||||
* Is a Linux/Unix shell command language
|
||||
* Is great for writing shell scripts that use command line interface (CLI) utilities, utilizing output from one command to another (piping), and executing simple tasks (up to 100 lines of code)
|
||||
* Can utilize command-line commands and utilities as-is
|
||||
* Has better startup time than Python but poor execution time performance
|
||||
* Does not come preinstalled in Windows; your script might not be compatible with multiple operating systems, but Bash is the default shell on most Linux/Unix systems
|
||||
* Is _not_ fully compatible with other shells (e.g., csh, zsh, fish)
|
||||
* Piping ("|") CLI utilities like sed, awk, grep, etc. can slow its performance
|
||||
* Lacks many functions, objects, data structures, and multi-threading, which limits its use for complex scripting/programming
|
||||
* Lacks good debugging tools and utilities
|
||||
|
||||
|
||||
|
||||
### Python
|
||||
|
||||
* Is an object-oriented programming (OOP) language, so it's more general purpose than Bash
|
||||
* Can be used for almost any task
|
||||
* Works on most major operating systems and is also installed by default on most Unix/Linux systems
|
||||
* Is very similar to writing pseudo code
|
||||
* Has simple, clear, easy-to-learn, and easy-to-read syntax
|
||||
* Has lots of libraries, documentation, and an active community
|
||||
* Provides better error handling features than Bash
|
||||
* Has better debugging tools and utilities than Bash, which makes it a great language for developing complex software applications involving many lines of code
|
||||
* Applications (or scripts) can contain many third-party dependencies that must be installed before executing them
|
||||
* Requires writing more lines of code for simple tasks than Bash does
|
||||
|
||||
|
||||
|
||||
I hope these lists give you a better understanding of which language to use and when to use it.
|
||||
|
||||
Which language do you use more in your day-to-day work, Bash or Python? Please share in the comments.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/19/4/bash-vs-python
|
||||
|
||||
作者:[Archit Modi (Red Hat)][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://opensource.com/users/architmodi/users/greg-p/users/oz123
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/computer_happy_sad_developer_programming.png?itok=72nkfSQ_
|
||||
[2]: /article/18/7/admin-guide-bash
|
||||
[3]: /article/17/11/5-approaches-learning-python
|
@ -0,0 +1,64 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (MjSeven)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (Bash vs. Python: Which language should you use?)
|
||||
[#]: via: (https://opensource.com/article/19/4/bash-vs-python)
|
||||
[#]: author: (Archit Modi Red Hat https://opensource.com/users/architmodi/users/greg-p/users/oz123)
|
||||
|
||||
|
||||
Bash vs Python: 该使用哪种语言?
|
||||
======
|
||||
两种编程语言都各有优缺点,一些任务使得它们在某些方面互有胜负。
|
||||
![][1]
|
||||
|
||||
[Bash][2] 和 [Python][3] 是大多数自动化工程师最喜欢的编程语言。它们都各有优缺点,有时很难选择应该使用哪一个。诚实的答案是:这取决于任务、范围、背景和任务的复杂性。
|
||||
|
||||
让我们来比较一下这两种语言,以便更好地理解它们各自的优点。
|
||||
|
||||
### Bash
|
||||
|
||||
* 是一种 Linux/Unix shell 命令语言
|
||||
* 非常适合编写使用命令行界面(CLI)实用程序的 shell 脚本,利用一个命令的输出传递给另一个命令(管道),以及执行简单的任务(最多 100 行代码)
|
||||
* 可以按原样使用命令行命令和实用程序
|
||||
* 启动时间比 Python 快,但执行时间性能差
|
||||
* Windows 默认没有安装。你的脚本可能不会兼容多个操作系统,但是 Bash 是大多数 Linux/Unix 系统的默认 shell
|
||||
* 与其它 shell (如 csh、zsh、fish) _不_ 完全兼容。
|
||||
* 管道 ("|") CLI 实用程序如 sed、awk、grep 等可以降低其性能
|
||||
* 缺少很多函数、对象、数据结构和多线程,这限制了它在复杂脚本或编程中的使用
|
||||
* 缺少良好的调试工具和实用程序
|
||||
|
||||
### Python
|
||||
|
||||
* 是一种面对对象编程语言(OOP),因此它比 Bash 更加通用
|
||||
* 几乎可以用于任何任务
|
||||
* 适用于大多数操作系统,默认情况下它安装在大多数 Unix/Linux 系统中
|
||||
* 与伪代码非常相似
|
||||
* 具有简单、清晰、易于学习和阅读的语法
|
||||
* 拥有大量的库、文档以及一个活跃的社区
|
||||
* 提供比 Bash 更友好的错误处理特性
|
||||
* 有比 Bash 更好的调试工具和实用程序,这使得它在开发涉及很多行代码的复杂软件应用程序中是一种很棒的语言
|
||||
* 应用程序(或脚本)可能包含许多第三方依赖项,这些依赖项必须在执行前安装
|
||||
* 对于简单任务,需要编写比 Bash 更多的代码
|
||||
|
||||
我希望这些列表能够让你更好地了解该使用哪种语言以及在何时使用它。
|
||||
|
||||
你在日常工作中更多会使用哪种语言,Bash 还是 Python?请在评论中分享。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/19/4/bash-vs-python
|
||||
|
||||
作者:[Archit Modi (Red Hat)][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[MjSeven](https://github.com/MjSeven)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://opensource.com/users/architmodi/users/greg-p/users/oz123
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/computer_happy_sad_developer_programming.png?itok=72nkfSQ_
|
||||
[2]: /article/18/7/admin-guide-bash
|
||||
[3]: /article/17/11/5-approaches-learning-python
|
Loading…
Reference in New Issue
Block a user