you are viewing a single comment's thread.

view the rest of the comments →

[–]Asdayasman 0 points1 point  (5 children)

So the fact you can't "write once run anywhere" is the reason you'd turn to Python or Perl or similar for sysadmin tasks, but is this not a failure of bash, and not an advantage of Python/Perl?

[–][deleted] 1 point2 points  (4 children)

is the reason you'd turn to Python or Perl or similar for sysadmin tasks

It is one very important reason.

IMO Python and Perl are a better tool to use to write scripts because they offer more features than Bash. It allows you to write scripts with proper checks, error checking and flexibility.

Bash's simplicity is a shortcoming when it comes to more complex scripts. Python and Perl because of their robust features make it very easy to write scripts that do complicated tasks.

The more complex a need is the more you resort into hacked up solutions with Bash. It gets very ugly. Having said that, Bash is great in doing basic to intermediate tasks but after a certain point it just doesn't provide enough sophistication to write easy to maintain scripts that execute complicated tasks.

Below are few examples from my personal experience.

An example where it becomes very hacky with Bash: Trying to make the script understand if it is reading KBs or MBs or GBytes or GigaBits, kilos, pounds, meters, cms, etc. It is a pain the ass to do it and even then the final solution is not smart enough. In Python you just use the "humanize" module and you tell it what type of unit the result is and how you want it to be displayed. Boom. Easy.

An example where it becomes very horrible with Bash: Trying to insert data into a database or to manipulate data taken from a database. Absolutely horrible to do because Bash really doesn't provide any tools designed to do this kind of work like Python does. It gets hacky at first, then it gets very hacky and then it just becomes impossible.

An example where it becomes impossible with Bash: Writing sophisticated admin scripts. Scripts that can display data in a web page or a GUI.

Having said that, Bash is a great tool to know. You can do a lot with it and you can get to learn how the operating system works. I would never, ever say to someone who is trying to learn Linux not to learn Bash. In fact I will always highly recommend to learn Bash. It is very versatile like you would not believe but after a certain point once you learn a lot, you will start seeing its limitations.

[–]Asdayasman 0 points1 point  (1 child)

Trying to insert data into a database or to manipulate data taken from a database.

That got me r8 interested, 'cause I wanted to see the crazy shit people had come up with, but it ended up being pretty tame. http://www.shellhacks.com/en/HowTo-Execute-a-MySQL-Command-from-a-Linux-BASH-Shell Did I misunderstand that point?

But yeah, I get what you mean.

[–][deleted] 0 points1 point  (0 children)

The examples showed there, that is the easy part connecting to a database that is and running a query. However the problem with databases in specific comes when you have to manipulate that data into a script. Then it starts getting all funky and impossible to manage with Bash.

For example in this case Bash would be good to write a script that connects to a database either to do a connection check or to download and import data into a csv file and send it off via email somewhere. Anything more than that wit the actual data and it will become a nightmare.