Home > Back-end >  Bash vs python quick comparison sheet
Bash vs python quick comparison sheet

Time:10-08

Is there any website that gives python command for each bash command as a quick guide to learn python from bash scripting....
I have some knowledge in bash scripting, need to learn python..so would like to compare for each bash command what is the corresponding equivalent python command. looking for some quick sheet/guide to compare and practice .

CodePudding user response:

Bash and Python are very different things.

Bash is intended for calling other commands and shuffling their output around. The bash "language" itself includes some rudimentary constructs like conditionals and loops, but most of the work is done by other programs, and it is not well suited for writing complex programs. For example, it doesn't have proper error handling, exceptions or types.

Python is a multi-purpose programming language. It is intended for developing software using functions, modules and classes. You can write just "scripts" in Python, but this is only a convenience which is similar to wrapping your "script" in a single main function and using it as the entrypoint.

Python can do some Bash things. For example you can use subprocess.run to call other commands. However you will see that the syntax is quite different from bash, and things like pipes are much more complicated.

Doing most Python things in Bash is very difficult (types, objects, exceptions...), many people prefer to avoid using Bash when they can use Python.

https://rosettacode.org/ will have some comparisons of Bash and Python programs. However, this probably will not be useful to you because the languages have such different use cases. Often, implementing the same thing in both requires writing very strange code in at least one.

CodePudding user response:

My recommendation would be to just find a good online tutorial for learning python, and study that. W3schools comes to mind. Bash is frequently used for helping to automate command line tasks, etc. Python has many more applications and can draw from lots of libraries for specialized tasks.

  • Related