Bash Script: copybook

 

Although not a COBOL program, this script might be useful to some, therefore I am including it here.

After putting in some effort to extract Working-Storage definitions for several of my programs and placing them into copybooks to avoid having to do this every time I need to use one of the programs, I realized that I would either need some means to easily prompt myself about the contents of the copybooks when I needed to use them, or I would have to resort to creating and maintaining a paper copy of the copybooks. I haven't been maintaining paper copies of anything for years, in fact have been eliminating all the paper I can around me, so I needed a solution.  Now, although I am not a great Bash script writer, I have written a few, so I came up with what I believe is a simple script that provides adequate functionality.  And that is what you will find on this page.

To install the script, download it from:  copybook [md5: 063287ebcf3c54f36a545a13dc79a7ea].  Right click and save the script in the location where your system stores locally originated system scripts.  You probably will need to change the attributes to make it executable on your system.  You may need to edit the script to change where it looks for copybooks on your system, although I believe the GnuCOBOL installation will always create the location I have used, as I did not do anything to specifically set this location up.  Obviously this is written on a Linux system, but since Windows now incorporates some version of Bash, it may be useful on Windows systems also.  You can pipe the output from the script to less to assist in orderly viewing of a listing of a copybook, or redirect the output to a file.

Output from the script from a few test runs on my system:

jay@Phoenix ~ $ copybook                                    No operands defaults to showing syntax (same as --help)
copybook requires 1 or 2 argument:
         --help to show this message
  <or>   --list to show all copybooks in directory
  <or>   --show {copybook name}
jay@Phoenix ~ $ copybook --help                             --help as single operand shows syntax 
copybook requires 1 or 2 argument:
         --help to show this message
  <or>   --list to show all copybooks in directory
  <or>   --show {copybook name}
jay@Phoenix ~ $ copybook --list                             --list as single operand shows contents of copy directory
Contents of /usr/local/share/gnucobol/copy
ParseCSV.cpy
ParseKWsets.cpy
screenio.cpy
sqlca.cpy
sqlda.cpy
stringStats.cpy
stringWords.cpy
Y2K.cpy

jay@Phoenix ~ $ copybook --show stringWords.cpy             --show as first operand displays contents of copybook given as second operand
Contents of /usr/local/share/gnucobol/copy/stringWords.cpy
      ******************************************************************
      * Author: Jay Moseley
      * Date: September 11, 2019
      * Purpose: Table of fields returned from stringWords
      ******************************************************************
       *> Array returned to caller with extracted words:
       01  STRING-WORD-LIST.
           02  SWL-COUNT               PIC S9(4) COMP.
           02  SWL-ENTRY               OCCURS 400 TIMES.
               03  SWL-WORD            PIC X(25).
      ************************************************ end of copybook *

jay@Phoenix ~ $ copybook --show badfile.cpy                 --show with non-existant file as second operand results in error message
File badfile.cpy not found

This page was last updated on September 21, 2019.