2007-11-24

Why shell scripting sucks

Writing any program in shell script is like shooting in your own foot in my humble opinion. I am talking about Bourne shell and its descendants. Here are my reasons:
  • Having the default setting of globing '*' returning '*' instead of nothing when there is nothing to match is just plain wrong. Suppose I write a shell script that updates the modify time in all the files in a directory so I write 'touch *', if there are files it works as expected, but if there are no files it creates '*' file!
  • To test that a variable is equal to something you have to do: if [ x$1 = x-h ] that can not be a good programming language.
  • Lack of associative arrays, so it is not useful for anything but really basic scripts. (Bash 4.0 finally has support for associative arrays)
  • It is not compiled, but executed line by line (you may not know it but python is compiled to bytecode at runtime and the bytecode interpreted unlike Java where the bytecode is also compiled to machine specific code)
So, in my opinion you better stop doing any shell scripts and write java or python instead of a sucky shell script.
If anyway, you code a shell script please see Bash Pitfalls to know about all the common shell script mistakes you can make and always write robust shell scripts.

1 comment:

shevegen said...

Java is no solution because you could use C.

Python is ok.

Personally I use Ruby. The advantage is that I can happily use ALL of Ruby's power when I am on windows too (I am mostly on Linux, but i dont wanna be tied down to that plattform when I use only shell scripts)

Shell scripts are ugly and not elegant.