Skip to main content

By clicking Submit, you agree to the developerWorks terms of use.

The first time you sign into developerWorks, a profile is created for you. Select information in your developerWorks profile is displayed to the public, but you may edit the information at any time. Your first name, last name (unless you choose to hide them), and display name will accompany the content that you post.

All information submitted is secure.

  • Close [x]

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerworks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

By clicking Submit, you agree to the developerWorks terms of use.

All information submitted is secure.

  • Close [x]

Rexx and what it means for AIX

Easy, powerful cross-platform scripting

Cameron Laird (claird@phaseit.net), Vice President, Phaseit, Inc.
Photo of Cameron Laird
Cameron Laird is a long-time developerWorks contributor and former columnist. He often writes about the open source projects that accelerate development of his employer's applications, focused on reliability and security. He first used AIX twenty years ago, when it was still an experimental product. He's been an enthusiastic consumer of and contributor to a variety of memory debugging tools through that time. You can contact him at claird@phaseit.net.

Summary:  Nearly thirty years of growth haven't exhausted the potential of the REstructured eXtended eXecutor (Rexx) language. The first of the widely used "scripting" languages continues to expand its capabilities and platform range, and it makes for a particularly good match with AIX®.

Date:  13 Mar 2007
Level:  Intermediate
Also available in:   Chinese  Russian

Activity:  8783 views
Comments:  

What can the REstructured eXtended eXecutor (Rexx) language do for you as an AIX® developer or administrator? More than you might realize, particularly with the first official release late in 2006 of the Open Object Rexx (ooRexx) variant for AIX.

Much of what you need to know about this scripting language appears, in one aspect or another, in Listing 1:
Listing 1. Word counting in Rexx

      parse arg filein
      count. = 0
      do while lines(filein) > 0
          input = linein(filein)
          do n = 1 to words(input) 
              w = word(input, n)
              count.w = count.w + 1
              if count.w = 1 then word_list = word_list w
          end
      end
      
      do i = 1 to words(word_list)
          w = word(word_list, i)
          say w count.w
      end
    

This is an uncommented Rexx program. Can you guess what it does? I'll bet you can, even without ever having tried to learn the language. This program:

  • Opens a file whose name appears on the command line
  • Reads each line of the file
  • Breaks each line into words
  • Accumulates counts of each word
  • Reports the total number of appearances of each word

When run on a UNIX® machine with Rexx installed as Rexx word_count.Rexx draft.xml, the output looks like Listing 2.
Listing 2. Typical output from the word-count program.

	  .
	  .
	  .
      included 3
      in 55
      file 3
	  .
	  .
	  .
    

Don't worry if Rexx is not installed on your desktop; I'll come back to questions of availability in a moment.

Readable Rexx

The first lesson from Listing 1, then, is that Rexx programs are easy to read: They're a lot like the shell programs you already write, except they have better arithmetic and their associative arrays are potent. An associative array (also called hash, dictionary, stem variable, and so on) is an indexed datatype whose index can be "any" string, not just the integers used by C's arrays. In the count example program, a stem variable maps a word to the number of times that word occurs.

To use Rexx effectively yourself, you need to learn the language and access its references. That's also easy: There are plenty of Rexx resources available, including both on-line and printed treatments, available at no charge. The Resources section below, including several developerWorks articles, contains more than enough references to start you on the path to programming in this nearly thirty-year-old language.

If you typed Rexx word_count.Rexx draft.xml in the command line from above on most desktops, though, you'll quickly learn that Rexx simply isn't installed. If few modern computers offer Rexx in a default installation, is it worth your trouble to learn it? Let's review the other essentials of Rexx's "cultural role," so you can fairly make that judgment for yourself.

Rexx was crucial for Amiga and OS/2® desktops, and it remains a standard scripting language for large IBM hosts -- System z™, CICS®, and so on. IBM has offered Rexx as a product for AIX under several different terms during the lifespan of the operating system. Whatever particular versions you run, there are at least a couple of prominent implementations -- Regina and ooRexx, most likely -- that can be downloaded for your host. That's the next key fact about the language: There's a Rexx available for your computer, with few exceptions. Moreover, along with the "native" implementations of Rexx, every system that supports a Java™ Virtual Machine (JVM) can run Rexx because the NetRexx variant compiles directly to Java bytecodes.

Among other things, all this portability means that, if you work in Rexx on one computer or network, you'll be able to apply that knowledge wherever else you go. This is especially important for those with responsibilities that range over mainframes and smaller systems, which share so little else in their programming or maintenance models.

Integration with the operating system

Let's see what more Listing 1 teaches. Suppose you wanted your report sorted; how does Rexx do that?

ANSI Standard Rexx doesn't include a sort routine, function, or keyword. That should shock you; sorting is a requirement of many of even the simplest applications. The Rexx planners didn't simply overlook this reality, though. Instead, part of the essence of Rexx is to integrate closely with the command-line environment of its host operating system. Rexx regards every statement that can't be parsed as an assignment or instruction as a "native" command. To adjust Listing 1 to produce a sorted result, you need only write:
Listing 3. Sorted word counting in Rexx

    
    parse arg filein
    count. = 0
    do while lines(filein) > 0
        input = linein(filein)
        do n = 1 to words(input) 
            w = word(input, n)
            count.w = count.w + 1
            if count.w = 1 then word_list = word_list w
        end
    end

    
    tmpfile = "/tmp/mytempfile"
    stream(tmpfile, 'c', "open write replace")
    do i = 1 to words(word_list)
        w = word(word_list, i)
        oneline = w count.w 
        call lineout tmpfile, oneline
    end
    
    command = "sort" tmpfile
    address system command 
    do i = 1 while queued() \= 0
        parse pull line
        say line
    end
    

This example writes out the table of word counts to the tmpfile external file, and then relies on the sort external system command to sort the resulting report. AIX and other flavors of UNIX build in the command-line sort utility.


Listing 4. Example sorted report from Listing 3
	   ...
	along 1
	alongside 1
	already 3
	also 7
	   ...
     

Most modern Rexx installations build in their own sorting extension, and it's easy to define a subroutine that implements quicksort or bubblesort for those which lack it. Listing 3 is instructive because so much of Rexx usage has to do with parsing, managing, and rearranging results from other facilities. In environments that handle enormous datasets, it can make sense to have Rexx team with a specialized external sort command. The next Rexx fact, therefore, is Rexx expects to "partner" with system commands.

Doesn't this show how clumsy Rexx is, though? A shell program to produce a sorted list of word counts can be as brief and simple as:
Listing 5. Sorted word counting in shell

      FILE=$1
      TMPFILE=/tmp/$$

      for word in `cat $FILE`
      do
	  echo $word >> $TMPFILE
      done

      sort $TMPFILE | uniq -c
    

Isn't this a better solution?

For the immediate problem, yes, shell is better; it makes good use of the built-in uniq -c command. Even reformatting the report or simple filtering probably adds only a single line more to the sh source.

Shell starts to falter and stumble, though, when asked to do arithmetic or manage data structures more sophisticated than space-separated records. Rexx is practical for much more demanding projects than sh. ooRexx, in particular, builds in a base set of classes, including:

  • QUEUE
  • TABLE
  • ALARM
  • SET
  • MESSAGE
  • And a half-dozen more

ooRexx fully supports such aspects of object orientation as polymorphism, inheritance, and important libraries, such as TCP/IP and mathematics, so that Rexx programs can solve complex requirements. Even graphical user interface programming is possible with Rexx/Tk, Rexx/DW, or one of the other GUI libraries.

Now you know the basic facts about Rexx. If you're already fluent in a couple of dynamic languages and a modern shell, Rexx might not present much of an advantage to you. If, on the other hand, your daily focus is on something else and doesn't demand that you think in terms of metaprogramming or continuations, and especially if you work across a range of IBM systems, you'll want to read through the Resources section to learn more about Rexx.

Conclusion

Remember:

  • Rexx programs are easy to read.
  • You can find plenty of Rexx resources available.
  • Few modern computers offer Rexx in a default installation.
  • Rexx is available for your computer.
  • Rexx expects to "partner" with system commands.
  • Rexx is practical for much more demanding projects than sh.

Good luck with your Rexx career.


Resources

Learn

Get products and technologies

  • IBM trial software: Build your next development project with software for download directly from developerWorks.

Discuss

About the author

Photo of Cameron Laird

Cameron Laird is a long-time developerWorks contributor and former columnist. He often writes about the open source projects that accelerate development of his employer's applications, focused on reliability and security. He first used AIX twenty years ago, when it was still an experimental product. He's been an enthusiastic consumer of and contributor to a variety of memory debugging tools through that time. You can contact him at claird@phaseit.net.

Report abuse help

Report abuse

Thank you. This entry has been flagged for moderator attention.


Report abuse help

Report abuse

Report abuse submission failed. Please try again later.


developerWorks: Sign in


Need an IBM ID?
Forgot your IBM ID?


Forgot your password?
Change your password

By clicking Submit, you agree to the developerWorks terms of use.

 


The first time you sign into developerWorks, a profile is created for you. Select information in your developerWorks profile is displayed to the public, but you may edit the information at any time. Your first name, last name (unless you choose to hide them), and display name will accompany the content that you post.

Choose your display name

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerWorks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

(Must be between 3 – 31 characters.)

By clicking Submit, you agree to the developerWorks terms of use.

 


Rate this article

Comments

Help: Update or add to My dW interests

What's this?

This little timesaver lets you update your My developerWorks profile with just one click! The general subject of this content (AIX and UNIX, Information Management, Lotus, Rational, Tivoli, WebSphere, Java, Linux, Open source, SOA and Web services, Web development, or XML) will be added to the interests section of your profile, if it's not there already. You only need to be logged in to My developerWorks.

And what's the point of adding your interests to your profile? That's how you find other users with the same interests as yours, and see what they're reading and contributing to the community. Your interests also help us recommend relevant developerWorks content to you.

View your My developerWorks profile

Return from help

Help: Remove from My dW interests

What's this?

Removing this interest does not alter your profile, but rather removes this piece of content from a list of all content for which you've indicated interest. In a future enhancement to My developerWorks, you'll be able to see a record of that content.

View your My developerWorks profile

Return from help

static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=AIX and UNIX
ArticleID=201607
ArticleTitle=Rexx and what it means for AIX
publish-date=03132007
author1-email=claird@phaseit.net
author1-email-cc=

Tags

Help
Use the search field to find all types of content in My developerWorks with that tag.

Use the slider bar to see more or fewer tags.

For articles in technology zones (such as Java technology, Linux, Open source, XML), Popular tags shows the top tags for all technology zones. For articles in product zones (such as Info Mgmt, Rational, WebSphere), Popular tags shows the top tags for just that product zone.

For articles in technology zones (such as Java technology, Linux, Open source, XML), My tags shows your tags for all technology zones. For articles in product zones (such as Info Mgmt, Rational, WebSphere), My tags shows your tags for just that product zone.

Use the search field to find all types of content in My developerWorks with that tag. Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere). My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).

Try IBM PureSystems. No charge.

Special offers