Sun sets a poor example for UNIX culture

Posted 23 Mar 2005 at 23:18 UTC by ksb Share This

Sun's BigAdmin Newsletter is a vehicle to promote Sun products, focus on the benefits of Solaris and UNIX in general, and brand Sun as an OpenSource player. The Techie Toolbox should provide clever examples of problem solving using all these paradigms. I was quite disapointed when I read their example script to run a command on the last Sunday of a month.

Their code is at, which is about 67 lines of complex code. It does not run anything, ever, it doesn't do leap years correcly, but it does display an astonishing level of complexity.

If we want to show off UNIX we would use the tools that compute calendars, not code one in shell. We might use a text filter or two to show how pipes make script easier.

As a counter example, the last Sunday in a month is shown on cal's default display, and cut (or awk) can help filter out the noise, maybe:

cal | cut -c1,2 | grep '[0-9]' | tail -1
would be clear (if I wrote some prose to explain the thoughts behind it).

So a script like

# Guard the command in argv, only run on the last Sunday of the month.
[ `date +%d` -eq `cal | cut -c1,2 | grep '[0-9]' | tail -1` ] || exit 0
exec "$@"
Might be more to the point, and correct.

My focus here should not be on the example, but the lack of vision Sun has provided by promoting such a poor example of scripting. In terms of style (dead assignments like to BASE), utility (the script does nothing), and UNIX culture (as above).

I use a lot of Sun products and gear. I really like Solaris 10's features. I just wish Sun was more of a UNIX company.

Is it really that bad?, posted 25 Mar 2005 at 18:43 UTC by Mysidia » (Journeyer)

which is about 67 lines of complex code. It does not run anything, ever, it doesn't do leap years correcly, but it does display an astonishing level of complexity.

To me it looks like about 30 lines of fairly simple (not particularly clever) code, which runs $COMMAND on the last Sunday of every month when used correctly, although yes, it isn't right for February in a leap year, (its check against Year = 2004 is not sufficient to prevent an extra spurious execution sometimes).

ksb: Yes, your approach is much more elegant, compact, and characteristic of certain UNIX ideas than what the author who put that script on Sun's site came up with. But simplier? far from it.

I think it would probably be much easier to explain Sun's script to a UNIX beginner with some intermediate level of programming knowledge. The bigger script you linked to doesn't use fairly sophisticated tools like grep, cut tail, exec, and pipelines.

There is less that needs explanation because their solution is somewhat less than ingenious, which may be very appropriate for its context in whatever explanatory purpose they're using it (although they should have at least made it correctly do what it claims to do).

Also, while this may be a less than ideal example they have posted, it may just be that this particular script's author does not know what they are doing.

I don't find this example to be a very compelling basis to support the idea that Sun isn't a UNIX company.

This is clearly a troll, posted 26 Mar 2005 at 06:55 UTC by avriettea » (Observer)

And while I normally do not feed the trolls, this time, I found the hook ensnared and felt an urge to reply. First off, I get paid to answer questions about Sun's market viability, and second, I have been grilled nonstop recently by Microsoft executives about the viability and utility ot all manner of Unix. You might say I had done a lot of research on the subject lately. Read my diary for more.

Shell programming, like perl programming, is highly stylized. In the case of Sun in particular, if you will notice, things like Jumpstart are very complicated. Sun's init scripts and operating system shell components (% file `which which` for the curious) are hideously complicated. For two reasons. First, Solaris is hideously complicated (this isn't a bad thing, because the people who admin it are hopefully hideously smart, trained, competent, whatever). Second, Solaris has grown for, what, twenty years now?

If you are suggesting some other company is more capable of representing UNIX, or representing "the shell", you be sure to let me know. I might buy it if you told me IBM, but things about AIX are Very Wrong.

Please keep your trolling to diary entries.

Sun's shell programming is highly stylized... and wrong, posted 26 Mar 2005 at 10:46 UTC by tk » (Observer)

I happen to have a Solaris account at my school, so I checked out the "hideously complicated" thing called which. At one point it says

if ( "$arg:h" != "$arg:t" ) then            # head != tail, don't search
    if ( -e $arg ) then                     # just do simple lookup
        echo $arg
        echo $arg not found
if ( ! $?found ) then
    echo no $arg in $path

The "$arg:h" != "$arg:t" is obviously supposed to test if the argument to which is an absolute path. And the test is wrong: doing

which foo/foo

triggers the second error message, not the first.

First, there's the "fantasy Microsoft", now there's the "fantasy Sun". If you want to demonstrate just how great Sun is, you could've picked a better example.

Seems like a poor example, posted 30 Mar 2005 at 03:29 UTC by bondolo » (Journeyer)

Reading the original posted URL I had a suspicion based on the "submitted" in the URL and indeed it appears that the script is not authored by Sun, but by a third party contributor, the mysterious Peter Jones. The annotation on the script is:


Description: Run scripts or code on the last Sunday of every month. Enter the name of the script you wish to run on the last Sunday of the month in the $COMMAND variable and then run the last_sunday script from cron every Sunday.


Submitter: N/A

So it seems that Sun's crime, in addition to supposed bad taste, is to host other people's crappy open source software.

Have you consider leaving the technology industry and getting into public relations or politics? This is the lamest attack I've seen in a long time....

Do I detect a flight of monkey poo?, posted 1 Apr 2005 at 05:58 UTC by MartySchrader » (Journeyer)

Uh, you guys are starting to make the Common Lisp/Scheme fist fighters look like gentlemen. Stop bickering, children.

Is there a point to all this? If the shell is capable of solving simple scripting problems like this then how about showing the solution and not picking at each other's approach/favorite OS/products/technical abilities/lack of personal hygiene? Knock it off.

New Advogato Features

New HTML Parser: The long-awaited libxml2 based HTML parser code is live. It needs further work but already handles most markup better than the original parser.

Keep up with the latest Advogato features by reading the Advogato status blog.

If you're a C programmer with some spare time, take a look at the mod_virgule project page and help us with one of the tasks on the ToDo list!

Share this page