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.4 Command Structure and File Naming Conventions

    VMS is not case-sensitive in its interpretation of commands. It doesn't distinguish between upper and lower case characters. This is not true in UNIX, however. Commands must be entered in lower case characters only. The Shell will not understand characters that are in uppercase. Filenames are also case sensitive in UNIX. The file named MYFILE.DAT and the file myfile.dat refer to different files. One advantage of this is that you can have a much larger variety of filenames with fewer characters. Especially good if you don't like to type. This also has advantage over the filename conventions used by VMS. Directories and subdirectories are pointer files in both operating systems. When a subdirectory is created in VMS it is given the extension name .DIR automatically. UNIX files on the other hand do not distinguish between ordinary files and directories. Many VMS users have adopted a practice of naming new subdirectories in UNIX with all capital letters or the first letter being capitalized. This is not, however, standard UNIX practice. VMS Sample Session: $CREATE/DIRECTORY [.TEST] $DIRECTORY UNIX Shell Sample Session: $mkdir Test $ls Test It is possible in UNIX to maintain the same filename conventions that you used in VMS. The period (.) is a legal character in a UNIX filename. Some VMS users like to continue the practice of naming files using the same . extensions from VMS. Problems occur when default extensions are different between the two systems. For example, object files use the extension .OBJ in VMS but .o in UNIX. Another example is FORTRAN source code in UNIX the extension is .f and VMS uses .FOR. Note that .o and .f are UNIX conventions to facilitate file recognition and that UNIX commands do not assume file extensions as VMS does. Here is a list of commonly used extensions for both operating systems.
    VMS        UNIX    Definition                                  
    
                                                                   
    
    .OLB       .a      Library                                     
                                                                   
    .BAS       .bas    BASIC Source Code                           
                                                                   
    .C         .c      C Source Code                               
                                                                   
    .FOR       .f      FORTRAN Source Code                         
               .h      C header files                              
               .l      lex program                                 
                                                                   
    .OBJ       .o      Object Code                                 
                                                                   
    .PAS       .p      PASCAL Source Code                          
               .s      Symbolic Assembly Code                      
               .y      yacc program                                
                                                                   
    .EXE        a.out  Executable Image                           
                                                                   
    .ADA               ADA Source Code                             
    .B32               BLISS-32 Source Code                        
    .CLD               Command description file                    
    .COB               Cobol Source Code                           
    .COM               Commands for the language interpreter       
    .DAT               Data file                                   
    .DIS               Distribution list file for MAIL             
    .DIR               Directory file                              
    .EDT               Startup command file for EDT editor         
    .DOC               Documentation                               
    .HLP               Input source files for HELP Library         
    .JOU               Journal file created by EDT                 
    .LIS               Listing of text                            
    .LOG               Batch job output file                       
    .MAI               MAIL message file                           
    .MAR               VAX Macro source code                       
    .SYS               System Image                                
    .TMP               Temporary file                              
    

    7.5 File Management Commands

    This is a table of the more commonly used file management commands. Some of these commands have been covered elsewhere in this manual. The on-line manual command (man) can be used to get detailed information about any UNIX command. UNIX VMS Purpose Command equivalent ar LIBRARY Archive files awk TPU Pattern matching utility cat TYPE/APPEND Catenates and prints to terminal cd SET DEFAULT Change working directory chgrp SET FILE Change group ownership chmod SET PROTECTION Changes protection cmp DIFFERENCE Compares two files and reports first difference found cp COPY Create a new copy find DIRECTORY Locates within a directory structure ftp COPY Transfer to/from remote node grep SEARCH Finds a string ln ASSIGN Create a symbolic link ls DIRECTORY List contents of a directory merge MERGE Merge files mkdir CREATE/DIR Make a directory mv RENAME Moves or renames files od DUMP Octal, decimal, hex, ASCII dump pr PRINT/HEAD Prints files pwd SHOW DEFAULT Working directory name rm DELETE Removes or deletes files rmdir DELETE Removes a directory file sort SORT Sorts by a key tail EDIT/READ Outputs last part of file tar BACKUP Tape archive touch CREATE Updates file characteristics or creates null file tr EDIT Translates characters

    7.6 Metacharacters

    Characters that have special meanings to the Shell are known as metacharacters. Users should avoid using these characters in filenames as results might be unpredictable. We have already seen several metacharacters, for example, vertical bar (|), or the greater than (>) or less than (<). The function of metacharacters can be different depending on whether the Shell or a UNIX tool interprets the character. The following is a list of UNIX special characters and their VMS equivalent. UNIX Function VMS equivalent Char & Perform command in Background = Assignment operator = ; Command separator \ Continuation of command line - \m Literal translation of metacharacter m "m ' Turn off special meaning " ` Process immediately @ & run " Group characters into a single argument " # Comment follows ! * Wildcard filename substitution * ? Wildcard filename substitution single character % $ Argument substitution follows ' $# Argument count $$ Process id F$GETJPI("PID") $? Exit status $STATUS $< Read one line from standard input INQUIRE, READ . Current directory [] [] Selective filename substitution Note: Metacharacters unique to the C-Shell have not been included in this list to reduce confusion. Check C-Shell documentation for a complete list.

    7.7 Wildcards: Are They Really Wild?

    UNIX wildcards extend the features found with wildcards in VMS. The following table shows how UNIX expands wildcard definitions:
     
    UNIX example                   Meaning                         
    
                                                                   
     *             # All files in the current directory and one    
                     level below                                   
                                                                   
     .             # Files in the current directory               
                                                                   
                                                                   
     *.*           # All files that contain a period in the                         filename                                      |
                                                                   
     *.com         # All files in the current directory that      
                     end in .com                                   
                                                                   
     ?.com         # All files in the current directory that       
                     end in .com and have one character            
                     preceding the period                          
                                                                   
     name[xyz]     # All files in the current directory, namex,    
                     namey, or namez                               
                                                                   
     name[a-z]     # All files in the current directory namea      
                     through namez                                 
                                                                   
     name[a-z4]    # All files in the current directory, namea     
                     through namez and name4                       
                                                                   
    
    There are no absolute rules concerning the use of wildcards. The output produced by the wildcard expansion process is command dependent. For instance, the ls * command will list files in the current directory and the files in the directory in the next lower level as well. The wc * (word count) command will produce output for the files in the current directory only. Thus as you can see commands vary in how wildcards are expanded. Users and programmers can use wildcards in a similar way to the method of using wildcards on the VAX. UNIX will interpret *.com to mean any file in the current directory that ends in .com even though the extension has no meaning in UNIX.

    7.8 Summary

    The VMS and UNIX operating systems are similar in some respects. The VMS user must recognize that there are some fundamental differences. UNIX allows multiple processes and the user must learn to manage these processes. VMS usually manages a single process which processes commands in sequence. UNIX has a different command syntax. UNIX commands are already short and cannot be abbreviated like VMS commands. UNIX commands do not lend themselves easily to describe their function. For example, TYPE seems to describe the function better than cat in UNIX. Single letter options modify UNIX commands in a manner similar to VMS command qualifiers. UNIX has a different file and directory structure. You can address any file irrespective of the physical device using the absolute or relative pathname. UNIX has metacharacters which have special functions when interpreted by the Shell.

    Workshop 7

    This workshop will reinforce your understanding of the ideas presented in all the previous chapters. Login to the Multimax using the username and password given to you by the instructor. Each student is to complete the entire workshop. DESK EXERCISES 1. Convert the DCL command file found on the next page to BourneShell and run it. Helpful?? Hints: What does the VMS DCL command file do? Does UNIX Shell have a similar function? What does the UNIX command cut do? What does the UNIX command date do? Can this script be converted one line at a time? $ Today = F$cvtime("today",,"weekday") $ if today .eqs. "Monday" then goto monday $ if today .eqs. "Tuesday" then goto tuesday $ if today .eqs. "Wednesday" then goto wednesday $ if today .eqs. "Thursday" then goto thursday $ if today .eqs. "Friday" then goto friday $ go to weekend $ Monday: $ Write sys$output " " $ Write sys$output "Today is ''today' and there are 5 days until this weekend" $ Write sys$output " " $ exit $ Tuesday: $ Write sys$output " " $ Write sys$output "Today is ''today' and there are 4 days until this weekend" $ Write sys$output " " $ exit $ Wednesday: $ Write sys$output " " $ Write sys$output "Today is ''today' and there are 3 days until this weekend" $ Write sys$output " " $ exit $ Thursday: $ Write sys$output " " $ Write sys$output "Today is ''today' and there are 2 days until this weekend" $ Write sys$output " " $ exit $ Friday: $ Write sys$output " " $ Write sys$output "Today is ''today' and there is 1 day until this weekend" $ Write sys$output " " $ exit $ Weekend: $ Write sys$output " " $ Write sys$output "Today is ''today' and why are you working on a weekend" $ Write sys$output " " $ exit 2. Not all functions, especially calls to library functions, that exist in VMS have an equivalent call in UNIX Shell. An example of this is F$ELEMENT in VMS. Write a BourneShell script that will do the same job as F$ELEMENT and test it. If time remains and you want a further challenge: 3. Write a user interface to add and delete records to the phone.lis database. Query the user in a user friendly manner and check to see if the name is already in the database prior to adding it. That's all for this workshop. If you didn't finish because of time, that's OK, as long as you understand the process needed to do conversions.

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