Starting Over: Rexx As Enhanced Shell Scripting
I can hardly believe that it has been over a year since my last posting. I spent 8 months in Missouri, working six days a week, ten to twelve-plus hours per day. Since Rexx is not allowed in my employer's work environment, that meant little or no time to even look at the language. On top of that, I'm very much a beginner with this language. This blog is sort of a way of recording my journey and showing others how to get somewhere with it. And, of course, the resources to pick up the language are sparse and getting sparser.
Even so, I haven't done all that I could to learn the language. My earlier attempts used Regina Rexx--in part, because it is available in the Ubuntu repositories--which actually follows the standard well enough so that most of the examples you'll find in books will work. The problem I found there is that the language itself is rather thin in some areas. This is understandable, because the language was designed from the beginning as glue, to take the available tools that already exist and to chain them together into something that provides desired functionality.
As a cross-platform language, I really wanted something that was more WORA ("write once, run anywhere"). But I found that calling out to the environment necessarily involves platform-specific functionality that has to be rewritten whenever the platform changes. So this isn't the language I wanted, but I think it can still be useful, so let's try and find some uses for it, shall we?
Assumptions
In order for this to work, I have to make some assumptions. So I'm going to assume that you're using a similar environment to mine:
- Operating system: Gnu+Linux, in particular, I'm running Xubuntu 9.10 64-bit. I'll probably be converting over to ArchLinux in a month or two. Whether you're on a Ubuntu-family OS, Mint, gNewSense, Arch, Debian, Mepis, Fedora, Mandriva, PCLinuxOS, or Suse, it should be pretty much the same.
- The NetPBM image toolkit package. This is available for various Unix-like operating systems, and also for Windows. It should be available through your distribution's packaging system or from SourceForge. The documentation is online.
- ooRexx, the IBM-derived, object-oriented, open source version of the Rexx language. The current version is 4.0, available from your distribution's packaging system or from SourceForge The oorexx and oorexx-docs downloads are on this page. This could potentially work with Regina Rexx or another version, but this is what I'm using.
- Your $PATH variable is set properly, so that the above software list is available on your path.
Task 1: E-Mail Protection
As we all know, there are software "bots" that scan the Web, looking for e-mail addresses to add to the spam targeting lists. Unless you like the flood of "male enhancement" and other spam and scam messages, your best bet is to find another way to put your e-mail address online.
Using NetPBM at the command line, we could do something like this: pbmtext "yourname@example.com" | pnmtopng >emailimage.png. But unless you use this often, you'll spend more time on NetPBM's doc site than you wish.
#!/usr/bin/rexx
/* emailimage.rex - protect someone's e-mail from some spambots */
/* copyright - none */
/* sends pbmtext "yourname@example.com" | pnmtopng >emailimage.png to shell */
say "Please enter your e-mail address."
parse pull addr
say "Please enter a name for the file."
parse pull flnm
outstring = "pbmtext " addr " | pnmtopng >" flnm ||".png"
outstring
You should have a PNG file in the directory where you ran this script. You can upload it to a web site or find another place to use it. There are some other options which could be set. If you'd like to know more, read the docs for NetPBM.
I am hoping that this is the first of many little things that can help make your life a little easier. I don't currently own any Windows machines, so these examples might not work for Windows users. In particular, on non-Unix platforms, the first line (#!/usr/bin/rexx) should be removed.
Powered by ScribeFire.


Nice post. :)
ReplyDeleteIn fact it is not necessary to remove the first line in Windows.
The Windows console (cmd.exe) uses the file association system of Windows for opening the interpreter (Open Object Rexx or Regina): if you write "hello.txt", the file is opened with Notepad; if you write "hello.rex", the script is executed exactly in the same way that it is executed when you click in the icon...
The PATHEXT environment variable in Windows eliminates the need of the extensión. If PATHEXT is ".COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.REXX;.RX;.REX", then if you write "hello", the files "hello.com", "hello.exe"... "hello.rexx", "hello.rx" and "hello.rex" are searched in the PATH.
In OS/2 the line should be removed if we want use the interpreter of the operating system because the two first characters must be "/*" (and the extension ".cmd").
In mainframes there are another requeriments like put the word "REXX" in the first line.
Another thing about the "sha-bang" line. In Regina there are two versions of the interpreter called "rexx" and "regina". The first version can't use the SAA extensions (Rexx/SQL, Rxsock...) while the second version can. This is a problem when the script starts with "#!/usr/bin/rexx" and you want use SAA extensions.