Industry guru Dave Taylor offers tech support on technical and business topics, including iPhone, iPod, Microsoft Windows, Sony PSP, cellphones, online advertising, CSS, Web design, business, Unix, Linux, SEO, Mac OS X, and shell script programming.     


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!


More Useful Shell Script Programming Articles:
✔   Secretly capture screenshots on my Mac?
When I used to work on a Linux system, there was a utility we had that would let me take screen captures every...
✔   Parsing "id" strings in a Shell Script?
Hello Dave. I need a Bash shell script that creates a directories with the group names automatically when user logs in to the...
✔   Copy and Paste from the Mac OS X Command Line?
I am constantly running commands in Terminal.app on my MacBook and then copying and pasting the results into email messages or documents. Yes,...
✔   Script to test line lengths for Twitter compatibility?
I've been tasked with writing a series of tweets for a Black Friday marketing campaign and am finding it a bit tricky because...
✔   Shell script to convert lowercase to title case?
As part of a project I'm working on, I find myself deep in a Linux shell script, needing to have a subroutine that...

Let's stay in touch!
Sign up for my weekly AskDaveTaylor Newsletter and you'll receive even more tech and gadget help right to your inbox, along with exclusive news and industry updates. It's good stuff. I promise!
    Enter your name: and your email addr:  





Categorized: Shell Script Programming   (Article 9339, Written by )
Tagged: ada, algol, c++, fortran, linux, mac os x, pascal, perl, programming, shell scripts
Previous: How do I delete my Google Gmail account?
Next: How Can I Comment On My Facebook Fan Page As Myself?




Reader Comments To Date: 2

Gary the K said, on March 9, 2010 8:18 AM:

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.

tsolox said, on September 24, 2010 3:58 PM:

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.

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, Dave, for all your helpful information by buying you a cup of coffee!

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











I will never send you any unsolicited email. Ever.






Check This Out Too...

 
Look for Answers
Need Help? Ask Dave Taylor!


Follow Me on Pinterest

Find Me on Google+
ADT on G+
© 2002 - 2013 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. Further, 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. My lawyer says "Thanks".
"Ask Dave Taylor®" is a registered trademark of Intuitive Systems, LLC.