Replacing UDelVM Execs with Unix Command Scripts: Introduction

Command execs on UDelVM typically specify filedefs and then load and execute programs. The document describes how to convert these REXX execs into C shell command scripts for the UNIX systems.

To introduce command scripts, consider a simple Fortran program that reads from the terminal and writes to the terminal. Here is a listing of the program.

        dimension x(100)
        print *, 'Enter number of array elements to process (max 100)'
        read *, n
        do 10 i = 1,n
          x(i) =i**2 + i
          print *, ' x(',i,') = ',x(i)
  10    continue
        end
Assume that the program has been compiled and the executable code is in file "sample.exe".


A C shell command script with the bare minimum

First, create a file to contain the command script. This command script does nothing more than run the program.

   Command script file name: example1.cmd
   --------------------------------------

   #!/bin/csh -f
   #  All lines beginning with a "#", like this one, are comment
   #  lines.  The first comment line, however, is a special
   #  one which tells the UNIX system that you want the C shell
   #  to process the commands in this file.
   #
   #  This sample command file, runs the program "sample.exe"
   #  which reads input from the terminal and prints the output
   #  to the terminal.
   # 
      sample.exe

Next, make the command script executable by typing the "chmod" command:

  chmod +x example1.cmd
Finally, run the command script by typing

  example1.cmd

A Command Script that Uses Input/Output Files

Now let's modify the command script to allow for input/output via files, rather than the terminal keyboard and screen. We want the names of the files to be provided at execution time.

   Command script file name: example2.cmd
   --------------------------------------

   #!/bin/csh -f
   #  In this command file the input data comes from a file
   #  and the output is written to a file. These are two arguments
   #  provided at execution time.
   #  The first argument is the name of the input file.   
   #  Within the script, the "$1" refers to the first argument's value.
   #  The second argument is the name of the output file. 
   #  Within the script, the "$2" refers to the second argument's value.  
   #  
   #  Run this command script by typing
   #
   #    example2.cmd  inputfilename   outputfilename 
   #
   #  For example,
   #
   #    example2.cmd in.dat  out.dat
   #
       sample.exe < $1  > $2
Make the command script executable by typing the "chmod" command:

  chmod +x example2.cmd
To run this command script, with input from the file "input.dat" and output to the file "output.dat", type

  example2.cmd  input.dat  output.dat

An Interactive Command Script

This variant asks the user to specify whether the output should be sent to the terminal screen or to a file.

   Command script file name: example3.cmd
   --------------------------------------

   #!/bin/csh -f   
   #  This command file differs from example2.cmd
   #  in that this command file queries the user whether
   #  the output should be directed to the terminal or to a file.
   #
   #  The "$<" below means the value is to be read from stdin (the 
   #  terminal keyboard).
   #
   echo 'Do you want output to go to a file? (Enter yes or no)'
   echo " "
   set answer = $<
   echo " "
   if($answer == 'yes') then
     echo 'Enter the name of the file'
     echo ' '
     set outputfile = $<
     echo ' '
     sample.exe < $1 > $outputfile
   else
       sample.exe < $1
   endif
 
In this script, the symbol "$<" stands for stdin (terminal input); the variable "answer" is set to the value read in. The value of the variable "answer" is used later by prefixing its name with a "$" ($answer).

To run this command script with input file "in.dat" type

  example3.cmd in.dat
and respond to the query with either

  yes
  out.dat 
for output to the file "out.dat" or

  no
for output to the screen.


  ******************************************************************
  *                                                                *
  *                Correspondence to VS FORTRAN                    *
  *                                                                *
  ****************************************************************** 
  *                                                                *
  *        VS FORTRAN                           UNIX               *
  *        ==========                           ====               *
  *                                                                *
  *             Sample Execs Converted to a Command Scripts        *
  *             ===========================================        *
  *                                                                *
  *                                                                *
  * /* Sample Exec */              #!/bin/csh   -f                 *
  * filedef 5 disk in dat          # Sample command script         *
  * filedef 6 disk out dat           sample.exe < in.dat > out.dat *
  * load sample                                                    *
  * start                                                          *
  *                                                                *
  *                                                                *
  * /* Sample Exec */               #!/bin/csh  -f                 *
  * filedef 5 disk in dat           # Sample command script        *
  * say "Output to a file?"         echo 'Output to a file?        *
  * pull ans                        set ans = $<                   *
  * if ans = yes                    if($ans == 'yes')then          *
  * then filedef 6 disk out dat      echo 'Enter file name'        *
  * load sample                      set outputfile = $<           *
  * start                            sample.exe < $1 > $outputfile *
  *                                 else                           *
  *                                  sample.exe < $1               *    
  *                                 endif                          *
  *                                                                *
  ******************************************************************

University of Delaware
June 19, 1994