Should I stick with bash for advanced Linux automation scripts or switch to Python?

I have very simple knowledge of bash shell programming and you can perform simple tasks like backups etc.

Now I am thinking about solving more complex problems and must decide whether I should stick with bash and learn more complex topics or learn Python.

Since I have to spend time studying anyway, I would like to spend it on a language that will give me the most benefits.

Connected:

Python and / or Perl VS bash
Is there any advantage of using bash on top of Perl or Python?
Python vs bash - In what tasks do each of them outperform other performance metrics?

+6
source share
6 answers

Bash is quite effective when you know it well, but he has a lot of traps, and thus, it is difficult to get right. Bash is also very suitable for the task. In particular, this makes it easy to parallelize simple things.

Python, on the other hand, is a more understandable language, but it is not designed specifically for your task, so first it will be a little more detailed. Once you have developed your small library of features designed for your needs, it should be great.

+9
source

In those days, the shell (bourne, ksh, etc.) is used to combine unix tools for tasks such as moving / copying files, backing up / archiving, formatting / reporting, etc. Currently, our shell (bash, ksh +, zsh, etc.) has its own programming functions, such as mathematics, arrays, associative arrays, if / else, loops, etc., which allow you to develop complex (or simple) shell scripts to perform various tasks. In addition to the shell, there are also more advanced languages, such as Perl, Python, Ruby, etc., which you can use for general programming or system administration, etc. They have many libraries, such as CSV for parsing / writing comma-separated files, PDF libraries for generating PDF files, web scanners for analyzing web pages and extracting data, etc.

In general, my recommendation is to study the shell (for example, bash) and another of these languages ​​is Perl / Python / Ruby. (because they do the same, usually).

+2
source

I found that knowing bash closely is a very rewarding experience, especially. if you do a lot of things on the command line, because you can apply what you learn there every day.

+1
source

I use my own shell scripting language. I prefer bash, but csh, tcsh, korn shell, etc. Also suitable for this job.

+1
source

They are all the tools in your arsenal to help you get the job done. Keep in mind that bash will most likely be installed on 99.9% of the servers you are running on. Odds start to fall, as the movement with perl is probably 80% more likely that python will appear there, which is likely to be installed, but it will be an old version, and with ruby ​​you are likely to look at it by many people. :) Learn bash, like the back of your hand, it will make you more productive during the work day, even for the most common tasks that you can skip faster and get this lunch on time.

I don't knock on learning python (my personal second language), but you sit on the command line all day. In addition, your script will most likely be ported to most of the machines you are working on. Once you are happy with the bash script, you can upgrade to python or perl.

Learn how to use functions in bash because you will live and breathe them in most other languages. When do you understand the concept of loops, if / then etc. This is just syntax because the basics of programming are usually the same. if so, do another action with another action. Repeat these commands until this condition occurs. :)

0
source

It depends on the task. If you need to create backup files, you can use rsync if you need to run a script every b or c file, but newer than using make . Unix was created to deploy utilities as small a program as possible to complete tasks. Learning a little bash to bind them all together and have one utility output for another, long ways to go.

If you are looking for common scripts, for example, opening a text file, doing something with it and putting it somewhere else, or doing something complicated with each directory file, I would study learning Ruby. It is very easy to write a quick short code. If you already know JavaScript, I would look at a Node check. Node (. Js) - a wrapper around the Google V8 JavaScript engine. This is, in essence, basic programming for JavaScript with special objects for saving / opening files and performing other complex functions, such as outgoing HTTP calls up to launching your own web server.

0
source

Source: https://habr.com/ru/post/887001/


All Articles