Free tech support header

Why is shell script programming so fun?

Dave, can you tell me, how come I enjoy shell programming more than other types of programming (Javascript, Java or C)?


Dave's Answer:

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:

host=$(hostname)

(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:

who | grep mary

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!



Help others find this article at Del.icio.us, Digg, Netscape, Reddit, and Stumble Upon    

Subscribe!
Never miss another Q&A article! Click to subscribe: Add to Google Reader Add to My Yahoo! Subscribe in NewsGator RDF XML
Comments

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.

Posted by: Gary the K at March 9, 2010 8:18 AM

I have something to say, now that you mention it, but ...
Starbucks coffee cup I do have a lot to say, and questions of my own for that matter, but first I'd like to say thank you for all your efforts on this Web site by buying you a cup of coffee!

I do have a comment, now that you mention it!











Remember personal info?


Please note that I will never send you any unsolicited email. Ever.

While I'm at it, please note that by submitting a question or comment you're agreeing to my terms of service, which are: you relinquish any subsequent rights of ownership to your material by submitting it on this site.






Recent Entries
Search
I Need Help!



Join The Club!
Sign up and get free weekly updates, news on my speaking schedule, seminars, workshops and more. It's cool. Just do it. :-)

© 2002 - 2010 by Dave Taylor. All Rights Reserved.

Note: This web site is for the purpose of disseminating information for educational purposes, free of charge, for the benefit of all visitors. We take great care to provide quality information. However, we do not guarantee, and accept no legal liability whatsoever arising from or connected to, the accuracy, reliability, currency or completeness of any material contained on this web site or on any linked site.

[whiteboard marker tray]
"Ask Dave Taylor®" is a registered trademark of Intuitive Systems, LLC.