mirror of
https://github.com/LCTT/TranslateProject.git
synced 2025-01-07 22:11:09 +08:00
69 lines
3.4 KiB
Markdown
69 lines
3.4 KiB
Markdown
|
[#]: collector: (lujun9972)
|
||
|
[#]: translator: ( )
|
||
|
[#]: 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
|