Please contact or Mt Xia for assistance with all your shell programming needs.


  • 7. VAX DCL TO UNIX SHELL SCRIPT CONVERSION. Go to the bottom, first,previous,next, last section, table of contents.

    
    

    7. VAX DCL TO UNIX SHELL SCRIPT CONVERSION

    This chapter will describe the steps necessary to convert DCL command files into Shell scripts. It is not a one to one conversion and many features found in one operating system are not found in the other. This requires you to write shell scripts that emulate features of the other. This is especially true of VAX and UNIX. The best way to accomplish this is to know exactly what it is that the command file does in VMS and then write the equivalent function in a shell script. There are few features that are the similar and those will be examined. There is really no "best" way to approach this subject. VMS and UNIX are both unique operating systems. Much of the material covered in this course up to this point will be used in the conversion process. We will start with a list of standard UNIX tools and their VMS equivalents. This will give a you a flavor of the kinds of tools each operating system has to offer.
    Major Tool                  VMS             UNIX               
    
                                                                   
    Editors                     EDT             ed                 
                                TECO            ex                 
                                TPU             vi                 
                                                                   
    Communications              MAIL            mail               
                                REPLY           write              
                                PHONE           talk               
                                DECnet          ftp                
                                                telnet             
                                                                   
    Compilers                   FORTRAN         f77                
                                                cc                 
                                                                   
    Text Processing             RUNOFF          troff              
                                                nroff              
                                                awk                
                                                lex                
                                                                   
                                                sed                
                                                                   
                                SORT            sort               
                                MERGE           merge              
                                                                   
    Program Development         LINK            link               
    Tools                       DEBUG           adb/dbx            
                                LIBRARIAN       ar/ranlib          
                                DEC MMS         make               
                                                yacc               
                                DEC CMS         scs                
                                                                  
    Miscellaneous               DECalc          bc/dc             
                                DECspell        spell              
                                                                   
    
    As you can see from the above lists, both systems offer editors capable of screen or line editing capabilities. Both have interactive communications, electronic mail, networking, file transfer, remote command execution, and remote logins. These utilities and tools are standard to UNIX but require a license to run under VMS. The Digital Command Language (DCL) and the UNIX Shell (Bourne,C, or Korn) are command interpreters. That is, they are both programs that parse the command line and then pass control to other programs that are the kernel of the operating system.

    7.1 Processes

    When you login to either system the operating system will create a unique process. This process is given access to memory and CPU resources. The differences between the two operating systems with respect to multi-tasking needs explanation. Multi-tasking is concurrent processes initiated by a single user. When the user starts a terminal session the system initiates a single process called the PARENT process. It is possible to start multiple processes from the parent process. This is called spawning in VMS and forking in UNIX. The new process is called a sub-process in VMS and a child process in UNIX. This idea of "forking" a child process occurs frequently in UNIX. When UNIX creates a child process or VMS creates a subprocess different things occur. First, let's look at VMS. When the subprocess is spawned the parent goes to "sleep" until the user logs off from the subprocess. When the logoff occurs control returns to the parent. The VMS ATTACH command gives control back to the parent process and the subprocess goes to sleep. The point is that only one process is active at a time. The exception is the VMS RUN/PROCESS=name which will run a user-defined process at the same time commands can be issued at the parent process. In UNIX, you can run parent and children processes at the same time. A child process can fork another process and thus a process can be both a parent and child. Child processes are not restricted to user-defined images but can be any valid UNIX operation. UNIX processes that are running or stopped but not getting input from a terminal are said to be in background. When you begin a UNIX session the kernel gives you a copy of the shell. When you enter a command the Shell forks a child. That child then processes the command you entered. Note: some commands are executed by the Shell itself and no child is forked. This is a different concept from VMS, in which all commands are executed by the parent process. Once a subprocess is created the parent remains dormant until the subprocess completes. All the above parent and child processes use the standard default for input and output devices, the terminal. Input and output streams in UNIX are called standard input (stdin) and standard output (stdout). Standard error (stderr) also uses the terminal as it's default output. In order to redirect these streams from a terminal in VMS it is requires the assignment of the logical names SYS$OUTPUT, SYS$INPUT, and SYS$ERROR to a file or device. UNIX has a much nicer means of redirecting the input or output.

    7.2 Pipes

    A vertical bar (|) is used to redirect the output of a command to the input of another command. This is the power of UNIX. For example, we want to get a list of all currently active users, sorted in alphabetical order, and sent to the printer, how could that be done in VMS? Here's one solution: VMS Sample Session: $SHOW USERS/OUTPUT=A.TEMP $SORT/KEY=POSITION:40,SIZE:6)- A.TEMP SYS$PRINT Notice the need for an intermediate file called A.TEMP. Now how would this same requirement be met using UNIX. There is a command that will list the users that are currently logged on to the system. The command is who. Pipes allow the output of one command to be the input into another command. The output of who can be put into another UNIX command sort by a pipe. In a similar manner, the output of sort can be redirected to another command called lp. Thus the same problem can be solved using UNIX Shell in this way: UNIX Bourne Shell Sample Session: $who | sort | lp -dmtlzr Notice that there is not a one-to-one command conversion that is taking place here. The idea is to convert the process more than individual commands from VMS DCL to UNIX Shell.

    7.3 Input, Output, and Error Redirection

    Just as the VMS logicals SYS$INPUT, SYS$OUTPUT, SYS$COMMAND, and SYS$ERROR point at the terminal by default, so do the UNIX equivalents stdin, stdout, and stderr. The equivalent of the SYS$COMMAND in UNIX is the "Here is" document. UNIX uses a much more simplified method of redirecting input and output to or from a file. UNIX does not require the effect of an ASSIGN statement ahead of the redirection. UNIX uses a metacharacter that is included as part of the command line. Here is an example of both VMS and UNIX. VMS Sample Session: $ASSIGN/USER A.LIS SYS$OUTPUT $ASSIGN/USER INPUT.DAT FOR005 $RUN MYPROG The equivalent function can be written in UNIX Shell like this: UNIX Bourne Shell Sample: $myprog < input.dat > a.lis The point here is to see that the metacharacters < and > act as the input and output redirection symbols. Please don't get the idea that UNIX is much simpler than VMS DCL. That is not the case. They each have strong points and weak points, they are not the same. This is comparing apples and oranges. Here is a partial list of the metacharacters used by the UNIX Shells and their meanings. These can be useful when you try to redirect input and output.
    Character      Meaning                                         
    
    >        Redirect standard output (stdout)                     
                                                                   
    >>       Redirect and append standard output (stdout)          
                                                                   
    >&       Redirect standard output (stdout) and standard error  
             (stderr)                                              
                                                                   
    >>&      Redirect and append standard output (stdout) and      
             standard error (stderr)                               
                                                                   
    <        Redirect standard input (stdin)                       
                                                                   
    |        Redirect standard output (stdout) to another          
             command                                               
    
    These are the most commonly used redirection metacharacters. Notes: UNIX redirection only affects the command line on which the redirection character occurs. Error messages are not redirected and will appear on the terminal. If a file already exists, VMS will create a new version of the file with a higher version number. By default, UNIX will overwrite the existing file.

    Go to the top, first,previous,next, last section, table of contents.