Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there an advantage to using Bash over Perl or Python? [closed]

Hey I've been using Linux for a while and thought it was time to finally dive into shell scripting.

The problem is I've failed to find any significant advantage of using Bash over something like Perl or Python. Are there any performance or power differences between the two? I'd figure Python/Perl would be more well suited as far as power and efficiency goes.

like image 498
ManAmongHippos Avatar asked May 02 '11 15:05

ManAmongHippos


People also ask

Is bash more efficient than Python?

Performance-wise bash outperforms python in the process startup time. This shows a huge difference however bash execution time degrades quickly if it has to do anything sensible since it usually must call external processes. If you care about performance use bash only for: really simple and frequently called scripts.

Is bash faster than Perl?

So yeah, Perl will generally be a lot faster if you're doing anything that you wouldn't normally do in bash anyways.

What is the difference between bash and Perl?

Bash is a Unix shell and command language which is commonly used for system administration tasks whereas Python/Perl/Ruby is used for general-purpose programming. But all of these can handle all kind of problems and all have different strengths over the rest.


2 Answers

Two advantages come to mind:

  • Simplicity: direct access to all wonderful linux tools wc, ls, cat, grep, sed... etc. Why constantly use python's subprocess module?

  • I'm increasingly fond of using gnu parallel, with which you can execute your bash scripts in parallel. E.g. from the man page, batch create thumbs of all jpgs in directory in parallel:

    ls *.jpg | parallel convert -geometry 120 {} thumb_{}

By the way, I usually have some python calls in my bash scripts (e.g. for plotting). Use whatever is best for the task!

like image 95
Sebastian Avatar answered Oct 16 '22 12:10

Sebastian


Perl scripts are usually (if not 100% of the times) faster than bash.

A discussion on that: Perl vs Bash

like image 12
Mario Peshev Avatar answered Oct 16 '22 11:10

Mario Peshev