File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Linux / UNIX and the fly likes Brainstorm on script projects Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "Brainstorm on script projects" Watch "Brainstorm on script projects" New topic
Author

Brainstorm on script projects

Michael Ernest
High Plains Drifter
Sheriff

Joined: Oct 25, 2000
Posts: 7292

'Lo all -
I'm teaching a course in shell scripting this week, and while I really enjoy on teaching people how to write scripts, I'm running dry on ideas for them to try.
I'm hoping some visitors here might throw out an idea for a medium-to-tough, or maybe just "very interesting" problem to be completed using a shell program. (With any luck, some suggestions might even be serious).
The people I'm teaching are completely new to this, and I've forgotten what not-knowing-how-to-get-started feels like.
So, as an added problem, if any suggestions are really interesting, and I can solve them in a couple of hours or less, I'll post my work back here for all to share. Bear in mind I have an eagle eye for problems that sound like your average homework assignment.
Guy Allard
Ranch Hand

Joined: Nov 24, 2000
Posts: 776
Hi Michael -
You don't indicate which shell......
-Editing - use an easy editor, especially for users from Windows ...
-What is executable and what is not: ls -l, chmod, chown
-PATH, . xxx _versus_ ./xxx _versus_ xxx
-Output
-Input
-if/then: strings _versus_ numerics
-case statement
-'standard' stuff: grep, sed, awk (if they are already programmers)
-In closing mention: PERL, Python, Ruby, GUI Toolkits, and
if they are from a Win environment mention wsh.
Links to some ideas (I like the Rutgers one):
http://pegasus.rutgers.edu/~elflord/unix/bash-tute.html
http://linux.org.mt/article/terminal
http://steve-parker.org/sh/sh.shtml
I'm sure you can easily find more.
Good Luck, Guy
Michael Ernest
High Plains Drifter
Sheriff

Joined: Oct 25, 2000
Posts: 7292

Ah, I should have been clearer. We're focussed on Bourne and Korn to make things concrete, but I mean shell in the generic sense of a program that acts as a command interpreter, scripting language, display generator, text generator, interactive session manager, all that.
I'm not teaching from scratch by the way; I'm using Sun's SA-245 course material, which is just low on 'practical' examples (and I low on inspiration). I also have with me Kochan and Woods' book, the O'Reilly on sed 'n awk and Korn shell, and the notorious C Shell Field Guide.
So I have plenty of material; it's just boring to tread over the same examples all the time.
But I'll check out those links, see if I find something stimulating.
Incidentially, some things I add to the course:
- dtksh (which is wsh and ksh-93)
- I dis Perl a bit, 'cause it's fun
- I pay little attention to Python, Tcl, Ruby, et al, because it's too much for this class in five days and the premise is to use tools that come bundled with the operating system.
Leslie Chaim
Ranch Hand

Joined: May 22, 2002
Posts: 336
Originally posted by Michael Ernest:
... but I mean shell in the generic sense of a program that acts as a command interpreter, scripting language, display generator, text generator, interactive session manager, all that.
...
I'm using Sun's SA-245 course material, which is just low on 'practical' examples

Michael,
First, if you look at your quote it 'seems' contradicting and I was unable to get a clear grasp of what you are looking for. Luckily, you give the course name. I looked it up, here are some ideas:
A menu driven script using select
A script which get's the last time it ran and does appropriate updates
See below for a list of ad-hoc commands

vi $(ll *.c | awk '$0 ~ "Nov 12"{print $NF}')
TZ=GMT date
And if I may point you elsewhere and as you will gather from the end of that post, I hope you will agree that the best patch for awk is perl not nawk
Cheers,
Leslie
Please keep us posted


Normal is in the eye of the beholder
Michael Ernest
High Plains Drifter
Sheriff

Joined: Oct 25, 2000
Posts: 7292

Now that's an intriguing little statement you have there. I'll have to play with that.
It depends on your criteria, of course, but for my money ksh-93 beats Perl for performance, readability, and usability.
For sheer volume of ready-to-use code on CPAN, Perl has obvious strengths as a choice.
[ November 12, 2002: Message edited by: Michael Ernest ]
Michael Ernest
High Plains Drifter
Sheriff

Joined: Oct 25, 2000
Posts: 7292

Ok, Leslie, let's you and I tussle over some things here:
That perl line on the other site you mention: yes, it's clearly powerful. It's also in my view the least scrutable solution.
That brings me to the cliche harangue I give about perl code: its write-only nature. It seems like you never know what most Perl code does unless you already know what it does.
What I like about many of previous, more pedestrian examples is it takes very little time to see what's going on. That's key to people who are learning to write to an interpreter.
Thank you very much for turning me on to this site. I'll dig around there some more.
Off-tangent tangent: one thing David Korn stresses about any shell/interpreter program is that it must unfailingly handle strings of arbitrary length. One goal for that: being able to generate text, more specifically code, to some other HLL (or even assembler, if you want to get nutty about it) through it.
I think what I'll start working on, with that in mind, is a simple shell tool that will parse a .java source file and tell you what's in it in plain English. Too tedious a project for these guys, but hopefully it'll give them an idea of the power of such tools.
Go on, Leslie, hit me with your best shot.
Leslie Chaim
Ranch Hand

Joined: May 22, 2002
Posts: 336
Gee, overnight you became the Mapper This is one of the cases where I believe that less is more
Here we go:

Ok, Leslie, let's you and I tussle over some things here:

c l, but before I begin I'll declare myself as the loser, I am not trying to win anything I am just stating my opinions and they are certainly debatable. I'm just having fun here and I am just sharing it. I hope you find more fun in this then the dreaded MD forum. Oops, that's another opinion.

Now that's an intriguing little statement you have there.

To be perfectly honest that's not my idea, I just brushed it up a bit

It depends on your criteria, of course, but for my money ksh-93 beats Perl for performance, readability, and usability.

Well -- for that I shamelessly, and as a loser , asked for help.

That Perl line on the other site you mention: yes, it's clearly powerful. It's also in my view the least scrutable solution.

And you are doubly right. Nevertheless, people still fell they should really, really, really make time to learn Perl.
I have more to say but I had to split up my post...
[ November 14, 2002: Message edited by: Leslie Chaim ]
Leslie Chaim
Ranch Hand

Joined: May 22, 2002
Posts: 336
Ok here I continue ...

That brings me to the cliche harangue I give about Perl code: its write-only nature. It seems like you never know what most Perl code does unless you already know what it does.

I really wonder how Larry Wall would defend this statement. I must assume that you have not mastered Perl yet. Yes, Perl is highly idiomatic and, as I like to say, full of heavy thick slang, but that's the joy of Perl. BTW, here are some other examples, you just can't beat them with ksh:

Which plucks out key/value pairs of $data and stuffs them into %hash.
Here is one more:

This tokenizes the current input ($_, or $ARG) based on the regex, and returns into the array @non_null_tokens, all tokens including the delimiters!
The moral of the story is, that Perl's implicit contexts and concise data structure handling is tough to master. But once you do it's joyful, rewarding, you really feel creative, and best of all you solve your problems in a fraction of the time.
Seriously Michael, I wonder if after reading the Camel Book and chapter 7 of Mastering Regular Expressions by Jeffrey Friedl if you would still say this or dis Perl in any way.
To quote Jeff, "The magician merely understands something simple which doesn't appear to be simple or natural to the untrained audience"

What I like about many of previous, more pedestrian examples is it takes very little time to see what's going on. That's key to people who are learning to write to an interpreter.

Ok, now we are getting back to the original topic and your point is well taken, for the sake of the people you will be teaching. I only pointed you to the other site so you should not dis Perl.
That said, I wonder if you would classify all of the Sample ksh functions and scripts as civil and how civilized is this:
<br /> How long does it take to explain something like:<br />
I can just conclude with the following, you can get carried away with the Shell as well as with Perl. The only difference is that Perl lends itself more to obfuscation, but I have already defended that sort-of.

Off-tangent tangent: one thing David Korn stresses about any shell/interpreter program is that it must unfailingly handle strings of arbitrary length. One goal for that: being able to generate text, more specifically code, to some other HLL (or even assembler, if you want to get nutty about it) through it.

Once again we get off the original topic, but let the fun continue
That's exactly why you should use Perl. For any text processing Perl is second-to-none. Nowadays, I believe the Shell has it's place for simple start up scripts or to streamline unrelated processes, such as to invoke a java application.

I think what I'll start working on, with that in mind, is a simple shell tool that will parse a .java source file and tell you what's in it in plain English. Too tedious a project for these guys, but hopefully it'll give them an idea of the power of such tools.

Yes, and you will leave them awestruck! I think that you are forgetting how-to-get-started feels like and you would leave those folks in a state of uncertainty.
But all kidding aside can you explain in ]I]English[/I] what is it that you are trying to do.
If you meant translation a source file to English then this is how you be converting C to English with Perl, but that's over my head. And if you wanted to THIS in the shell I would examine your head

Go on, Leslie, hit me with your best shot.

Not sure if I qualify, nevertheless this is the looooooooooongset post I've ever posted and it's got something to do with you . I just hope that you would address all the burning meaningful issues from the very forum that you are policing. RMI from start to Finish, was absolutely phenomenal, and we can't get enough of that.
This is over my head for now. I must get my RMI thing going . Thank you so much for all your help.
[ November 14, 2002: Message edited by: Leslie Chaim ]
Michael Ernest
High Plains Drifter
Sheriff

Joined: Oct 25, 2000
Posts: 7292

For the sake of a quick response: I am *so* flattered you took my tussling challenge head on. Winning or losing is beside the point really; that would be like having one thumb wrestle and never doing it again. I just enjoy hearing people defend their tools energetically; it makes it easier to see the limits of my own biases -- oh, ok, bigotries. And maybe I'm fixated on teasing people. Maybe.
In any event, there's a wealth of thoughts here that deserve a careful response, so I will come back to this, but later today.
I can't tell how guilty I feel about not getting even halfway to the Finish of RMI from Start to Finish; I *do* need to get back to that project. (whining)But it's hard! Two kids! A business to run! Tough economy! I want a poker room 3 miles from my house! I want to brew my own beer! I want to write really, really painfully awful poems that rhyme too much and set them to guitar music to annoy my neighbors! I don't want to shave and I don't want a beard! For Pete's sake, I don't want to do anything hard.
...
(/whining)
Ok, I think I'm over that now.
I can't tell you how hard and tedious it is for me to write that guide. Maybe if I could find a case of fat-free Mystic Mints, a CD player with a neural interface for song selection and a bare room for a few days, I could make progress on it. But it's hard, it's tedious, and even good, old-style Catholic guilt isn't getting me back to it.
But you're right; gotsta go back and finish what I started.
Sigh...
Michael Ernest
High Plains Drifter
Sheriff

Joined: Oct 25, 2000
Posts: 7292

Ok, so many things to answer to:
1) You're funny.
2) I'm *impressed* by the cogency and skill of the subscribers over at the HP site; that's a fantastic pool of resources and concise writers. That the very first respondent knew how ksh-93 and Perl stacked up floored me. Wow.
2a) I dispute very few points your colleagues brought up in that discussion. Portability is not a major difference: ksh-93 runs on Windows and Linux just fine. Distribution, of course, is another thing, as is the wide availability of helper libraries. I believe I conceded those points already though.
2b) Someone should tell that one guy that looping echos is rather silly. We want to focus on the power of expensive operations. Wide differences even in things like counter increments easily get lost in far more expensive instructions.
3) Yes, I'm no master of Perl. The kinds of jobs I often take require me to fix or improve hack code in a hurry. When I see a Perl gig, I usually want no part, so I get no practice, and I'm not likely to play with something that gives me headaches at work. I already despise more C programmers than I like on similar grounds...yeah, that's it, I'm afraid if I master Perl I'll just make more enemies with my impossibly high standards. That's the ticket.
4) There's *nothing* you can do with straight Perl that can't be done with ksh-93. But, I don't want to duel with examples just yet. The two you show are nice in Perl; they're actually quite similar in ksh-93 and [mng ]awk
5) At one point I had both the Camel and Llama (Dromedary?) books. I liked them. But they didn't fire me up. As for regular expressions, those aren't Perl constructs, of course. They're a platform-independent standard, so regex for Perl looks no different for ksh. /^XXX/ is a line that starts with 3 X's in either one.
6) Hee hee, I agree with you on some of David Korn's sample scripts. Not designed to impress a newcomer, I'm sure. I don't like them much myself. I set out to rewrite into sexier (i.e., more readable, compelling) code once, but I can't find my versions. Sent them to DK himself once; he was polite and I guess not too annoyed by my impertinence.
7) I realized later what I was bringing into the mix with my Java-source-to-English transliteration idea: lexing, parsing, a grammar, etc. Your point brought me back to my original problem in post #1: I've forgotten what it's like to be starting out with this stuff: that's why I came fishing for ideas in the first place. Problem is, no one takes "advanced" shell scripting classes, so where do you go for more interesting ways to teach this stuff?
Again, thanks for taking me and my opinions head on. I had a lot of fun with this.
Sigh, now back to my dingy corner in Distributed Java, I guess...
Leslie Chaim
Ranch Hand

Joined: May 22, 2002
Posts: 336
Indeed, it was fun, and a good learning experience as well. It's odd where this conversation ended up while at the same time we keep making references to the original post.
I just want to reveal a couple of points :roll: :roll: :roll: :roll:
  • I feel that my stalking was successful!
  • I went to the 'other site' for help simply because I was lazy. BTW, there's a real lively discussion which you may want to see.
  • This site is still great
  • I'm toying with the idea to reveal to the other folks who 'this' guy is.
  • Please let me when you will publish your book with this high standards.


  • Good luck with your course; have a nice weekend.
    [ November 15, 2002: Message edited by: Leslie Chaim ]
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Brainstorm on script projects
     
    Similar Threads
    Your opinion # 1
    Teaching Java Talk @ JavaOne
    Trouble with student expectations
    Blocking user input
    Advanced forum becoming worthless