[nycbug-talk] Shell Newbie

N.J. Thomas njt at ayvali.org
Wed Apr 12 10:56:43 EDT 2006


* Huy Ton That <huyslogic at gmail.com> [2006-04-12 09:58:11 -0400]:
> I've always used the bash shell and wanted to get into some shell
> scripting.  Before I started, I curious to see if anyone had any
> feedback as far as other shells are out there

Write all your shell scripts in Bourne, unless you are absolutely sure
you won't need to port your script anywhere -- shell scripts have a
tendency to long outlive their originally intended lifespan.

/bin/sh can sometimes be a pain, but the gains in being able to run your
script on practically any Unix machine anywhere are well worth it. I
wrote a script yesterday for work where arrays would have been a nice
feature, but I had to get by with using crazy tricks like:

    i=0
    while [ "$i" -lt "$NUM_MACHINES" ];
    do
        i=`expr $i + 1`;
        eval mach="\${NAME_MACHINE_$i}"
        ...
    done


But in the end, I'm confident that the script will run anywhere with a
minimal amount of tweaking. (FWIW, for some reason, Linux users seem to
be especially bad at writing shell scripts (usually in Bash) that seem
to work only on Linux. I never understood why this is, perhaps /bin/sh
on all Linux boxes are just links to /bin/bash?)

Thomas

-- 
N.J. Thomas
njt at ayvali.org
Etiamsi occiderit me, in ipso sperabo



More information about the talk mailing list