Does Unix on Bama have REXX?
REXX is the scripting language used on UA1VM to run series of commands. We now have a Unix version of REXX so that UA1VM users might be able to bring scripts over to run them. It is not a 100% emulator, however, so modifications may still be needed in the scripts. There is a man page. Just type
man rexx
Now, in spite of the title of this Tipsheet, that's all we're going to say about REXX. For users generating new scripts, it is really not needed. Unix already has several very powerful scripting languages of its own; the shells (and we have added Perl, too). Any series of shell and/or unix commands can be put into a file, then when the file is executed, those commands will be run. The shells have the capacity for flow control, as in "if-then-else", for-loops and while-loops, they can read and write data from and to files, and they let you define functions, just as in any programming language. We've already seen a bit of shell programming in Tipsheet Vol. 2, No. 1, "Horrible, Repetitive Unix Jobs." Let's take another look at that script:
#!/bin/ksh files=(ls *.html) for filename in $files; do echo processing $filename sed -e "s+UA1VM+bame+g" $filename > tmp mv $filename $filename_old mv tmp $filename done
The steps were explained in the original Tipsheet, but a short review is in order. This script gets a list of all the html files in a directory, searches through them for UA1VM with "sed" and replaces UA1VM with bama, saves the old file under the original name with "_old" added on, then saves the edited file under the original name. This was an example of how to let the computer do a laborious editing job through the use of a script.
Scripts can be used to provide the input that would otherwise have to be typed in. Suppose you have a program to be run many times. Each time it asks the same questions, only the responses change. Let's say the program, named "progname" in this example, wants an input file name and an output file name. It can then be run automatically like this:
progname <<EOF inputfile1 outputfile1 EOF progname <<EOF inputfile2 outputfile2 EOF
and so on, for as many times as you need to run the file. Then run the script in the background (see Tipsheet Vol. 2, No. 5) and go to lunch. For example, you could type
nohup sh scriptname &
where scriptname is the name you gave the file with commands. The "nohup" is there to keep the script running even after you log out. Users of the csh and tcsh don't need to use "nohup". If the program, "progname", produces any output that you want to keep you would redirect it, either in the script or when you run the script. For instance
nohup sh scriptname > script.log &
would run the script and save any output in a file called script.log. By default, nohup sends the output to "nohup.out". Users of the csh and tcsh will definitely have to redirect the output to save it.
With a script, you can run any other script, any compiled program, any Unix command, and any shell command appropriate for the shell you are using. The shell you choose to use to run your script is up to you. In the last example, since there were no script-specific commands, we could have used any one. The example used "sh". In general it is felt that "sh", and it's more modern counterparts, "ksh" and "bash", as better for writing scripts.
To control which script language is going to be used you need to put the line
#!path-to-script
where path-to-script is the path to the script you want to use. Legitimate values are "/bin/sh", "/bin/ksh", "/bin/csh", "/usr/local/bin/tcsh", "/usr/local/bin/bash", and "/usr/local/bin/perl". There are other scripting languages for Unix that may be added in the future, such as "Expect" and "tcl/tk" (pronounced "tickle"). "Expect" can be used to write a script that looks for various questions that a program might ask and give the appropriate response. The other language, "tcl/tk", is more useful for writing Graphical User Interfaces (GUIs). If you have an application that requires these, please let us know via email to help.desk@mail.ua.edu.
Here is one last handy example script. It will rename the suffix on a file. This is useful when you have transferred over large number of files from UA1VM and they need to be renamed. This example will change any suffix to any other suffix when given on the command line. The syntax it uses requires that it be done by the Korn shell (ksh). If you try this, note that all the spacing on the "if" statement must be left as-is.
#!/bin/ksh
if [ $# = 2 ]; then
files=(ls *.$1)
for filename = $files; do
mv $filename ${filename%.$1}.$2
done
fi
It even checks to make sure it is given the two suffixes. Change it to be executable and you're off. Want to change all ".fortran" suffixes to ".f"? Just type this
scriptname .fortran .f
where "scriptname" is the name you have given your script.
In general, any REXX script you have on UA1VM can be translated to run on Bama. That is, you can do the same things you have been used to doing. There is no automatic translation program, however, so you will have to learn a little scripting. Any general Unix book will help you to do this. In the end, you can expect your Unix scripts to look simpler than their REXX counterparts.
© 1998, The University of Alabama. The information included here is for the University of Alabama central computing facility as it was configured on the document date. It may or may not apply to other Unix systems.

