Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Shell scripting vs programming language

For alot of the tasks I have to do I find myself having to choose between making the program using a Shell Script in Linux or a programming language such as Java or Groovy. Does anyone havce any experience about how I should choose one over the other and why?

like image 353
yazz.com Avatar asked Feb 10 '11 10:02

yazz.com


3 Answers

Shell scripts are excellent for concise filesystem operations and scripting the combination of existing functionality in filters and command line tools via pipes.

When your needs are greater - whether in functionality, robustness, performance, efficiency etc - then you can move to a more full-featured language. They tend to offer some combination of:

  • type safety
  • more advanced containers
  • better control over variable lifetimes and memory usage
  • threading
  • advanced IPC like shared memory and TCP/IP
  • full binary I/O capabilities, memory mapped file access etc.
  • access to OS APIs and myriad powerful libraries
  • better readability and maintainability as the project size increases
  • support for more advanced programming paradigms: Object Orientation, Functional Programming, Generative Programming etc.
  • better error-checking before your program starts running, hence less dependent on test case coverage
like image 97
Tony Delroy Avatar answered Oct 23 '22 04:10

Tony Delroy


@Tony provides an excellent list of pros and cons. I would add one more general point - shell scripts, because they are so handy, risk displaying the "there is nothing more lasting than a temporary solution" characteristic with all the attendant problems of maintenance when somebody else needs to use it.

like image 37
Chris Walton Avatar answered Oct 23 '22 03:10

Chris Walton


Shell script is the most intuitive way to have a "glue" on your system. However, it does not have some useful concepts, like inheritance and modularization, that languages like Python (which is very used to "glue" systems too) have.

True, the use of language depends basically on the task you are trying to do. For the most cases I've worked, shell script worked well, although I'm using a lot of Python to accomplish system related tasks. I don't think that Java would be an alternative in this case. Probably Groovy would be, but not Java (I mean Java as a language, not Java as platform.)

In a sysadmin view, I think Python and Ruby are awesome languages. Not only because of dynamic typing and the lack of need to be compiled, but because tools like Fabric, Capistrano, Puppet, and a lot of others which makes a sysadmin's life a lot easier :-)

like image 2
Herberth Amaral Avatar answered Oct 23 '22 03:10

Herberth Amaral