Dave, can you tell me, how come I enjoy shell programming more than other types of programming (Javascript, Java or C)?
Well that’s an interesting question!
I’ve programmed in dozens of languages, ranging from the classics (BASIC, Algol, Fortran, Pascal) to more modern languages and even obscure ones (Ada, APL) and I have to agree with you, Scott, that there’s something about shell script programming in the Linux environment that’s easy, fast, and great fun.
I think part of it is that since it’s incredibly easy to access regular Linux commands from within a shell script, it’s one of the few languages where you start out already knowing how to do the complicated things from just using the command line.
Want to find out the hostname of the computer? Just use “hostname” as you would on the command line. Want to assign it to a variable? Easy:
(or you can use the older notation of `hostname` if you’d prefer)
There’s also almost no overhead, no declarations, no need to define variables in advance, so you can write shell scripts as short as one line:
Since it’s an interpreted language rather than a compiled one, it’s also really fast to work with and your development cycle is edit -> run -> edit -> run until you get it to work as you desire. Even better, as you learn more about Linux or add additional command packages like ImageMagick to your system, you gain lots more control and capabilities in your programming environment too.
I’ve always referred to shell script programming as “lightweight” because it’s really fast to get started, easy to use, and perfect for short apps and prototyping. Would I write a compiler as a shell script, or a GUI system? No, I think that’d be a huge amount of work and is going to be a pain in the booty. But would I write games, system utilities, and useful little ‘bots as shell scripts? Heck yeah, I have a whole book about it: Wicked Cool Shell Scripts.
Now, the honest other side of the coin: there are no debugging capabilities in the shell to speak of, and since you can do any command, you can also make grievous mistakes without it complaining, like deleting the file you’re trying to parse. So it’s not all milk and honey, proverbially or otherwise.
Still, if you have a Mac OS X system or a Linux box, you might well want to spend some time playing on the command line, then jump in to writing a few short, simple shell scripts. You’ll be amazed how little like programming it feels and how much faster and more fun it is than writing complicated C++ or Ruby functions!
According to the German philosopher Friedrich Nietzsche, two forces must co-exist in a certain proportion. He calls it Apollonian vs Dionysian. The Apollonian,just like the greek god Apollo, is toward the tendency of form and order, of prediction and oracles and restraint, and preparation. This is just like Java or C#/C/C++ in which one’s programming intent is properly prepared thru a compile-link steps and the language syntax elements supporting OOP and error exception handlers. The Dionysian, is from greek god of wine Dionysius, which has tendency toward chaos and disorder and the lack of restraint, all that is free flow like perl and bash.. no preparation, just pure kinetic energy. The proper proportion of these two, according to Nietszche, is the source of arts. That’s why i learn Java/C#/C/C++/COM and then bash/linux/python embracing both Linux and Windows. A preference of one over the other is weakness.
Dave, I have to agree with you….I’ve dabbled in Cobol, Fortran, PL1 and RPG before “discovering” UNIX shell scripting in 1995. I’ve moved into Linux and still really enjoy it.