filmov
tv
When to use Bash and when to use Perl/Python/Ruby? (11 Solutions!!)

Показать описание
When to use Bash and when to use Perl/Python/Ruby?
The Question: We are doing all our scripting with Bash so far, but I'm starting to feel a bit
silly about it. While we can of course do everything we want with Bash (it's
quite powerful), I'm starting to wonder if we shouldn't use a proper scripting
language (in our case most likely Ruby) instead.
How do you decide when to use Perl/Python/Ruby over Bash for a script? I don't
think an init script with Ruby makes sense, but how about a slightly longer
script that adds email accounts?
Solutions: Please watch the whole video to see all solutions, in order of how many people found them helpful
== This solution helped 4 people ==
Bash is a Unix shell it includes a scripting language. It is rather command
processor. you control the way how you run commands, you actually run them.
Perl/Ruby/Python are general purpose languages.
When you want a shell script, you use Bash
If you want more complex task or not related to shell. Use Python etc.
I would never compare these languages actually. Python etc. are portable. You
can run them anywhere. Bash is for Unix only.
Python etc. have tons of reusable libraries solving millions of tasks.
It's almost the same if you ask. "When to use Paint and when to use Photoshop"
For processing emails I would use Ruby, again, because it has a lot of reusable
libraries.
But the best way would be combine bash and ruby. That would be right. Like you
create a email processing script in ruby and bash script would invoke that ruby
script and run other commans ds.
So whenever you need command processor you use bash. You run unix commands and
control them.
***** UPDATE after 7 years (Mar 2019) *****
While the main part of my answer didn't change I would like to point out that.
Bash is a powerful scripting language too. For text processing it could an
absolute legit choice.
Please read mkaito's comments below. They are all completely true.
== This solution helped 44 people ==
Given a problem that both can handle, you'll want to use the one you're most
comfortable with. Ultimately, there are a lot of small details, and only
experience can teach you to see them.
Bash is a general purpose scripting language just like Python, Ruby, Perl, but
each has different strengths over the rest. Perl excells at text analysis,
Python claims to be the most elegant of the bunch, Bash scripts are excellent
at "piping stuff around", if you know what I mean, and Ruby... well, Ruby is a
little special in a lot of ways.
However, the differences between them only really matter once you have a
healthy amount of scripting experience under your belt. I suggest you pick one
language and push it to it's limits before moving to the next. You can do a lot
in a shell script, more than most people would admit. Any language is just as
hard as you want to make it. After you've written a couple things in it, every
language is "easy" to you.
Being familiar with the shell pays off quickly if you live in Linux, so maybe
you want to start with that. If you find a task you that is impossible or
impractical to solve in a shell script, use something else.
Also, bear in mind that learning shell scripting is very simple. The real power
of it lies in other programs, like awk, sed, tr, et al.
The Question: We are doing all our scripting with Bash so far, but I'm starting to feel a bit
silly about it. While we can of course do everything we want with Bash (it's
quite powerful), I'm starting to wonder if we shouldn't use a proper scripting
language (in our case most likely Ruby) instead.
How do you decide when to use Perl/Python/Ruby over Bash for a script? I don't
think an init script with Ruby makes sense, but how about a slightly longer
script that adds email accounts?
Solutions: Please watch the whole video to see all solutions, in order of how many people found them helpful
== This solution helped 4 people ==
Bash is a Unix shell it includes a scripting language. It is rather command
processor. you control the way how you run commands, you actually run them.
Perl/Ruby/Python are general purpose languages.
When you want a shell script, you use Bash
If you want more complex task or not related to shell. Use Python etc.
I would never compare these languages actually. Python etc. are portable. You
can run them anywhere. Bash is for Unix only.
Python etc. have tons of reusable libraries solving millions of tasks.
It's almost the same if you ask. "When to use Paint and when to use Photoshop"
For processing emails I would use Ruby, again, because it has a lot of reusable
libraries.
But the best way would be combine bash and ruby. That would be right. Like you
create a email processing script in ruby and bash script would invoke that ruby
script and run other commans ds.
So whenever you need command processor you use bash. You run unix commands and
control them.
***** UPDATE after 7 years (Mar 2019) *****
While the main part of my answer didn't change I would like to point out that.
Bash is a powerful scripting language too. For text processing it could an
absolute legit choice.
Please read mkaito's comments below. They are all completely true.
== This solution helped 44 people ==
Given a problem that both can handle, you'll want to use the one you're most
comfortable with. Ultimately, there are a lot of small details, and only
experience can teach you to see them.
Bash is a general purpose scripting language just like Python, Ruby, Perl, but
each has different strengths over the rest. Perl excells at text analysis,
Python claims to be the most elegant of the bunch, Bash scripts are excellent
at "piping stuff around", if you know what I mean, and Ruby... well, Ruby is a
little special in a lot of ways.
However, the differences between them only really matter once you have a
healthy amount of scripting experience under your belt. I suggest you pick one
language and push it to it's limits before moving to the next. You can do a lot
in a shell script, more than most people would admit. Any language is just as
hard as you want to make it. After you've written a couple things in it, every
language is "easy" to you.
Being familiar with the shell pays off quickly if you live in Linux, so maybe
you want to start with that. If you find a task you that is impossible or
impractical to solve in a shell script, use something else.
Also, bear in mind that learning shell scripting is very simple. The real power
of it lies in other programs, like awk, sed, tr, et al.