From:	CSBVAX::MRGATE!@KL.SRI.Com:OC.PEDHEM@CU20B.COLUMBIA.EDU@SMTP 22-AUG-1987 00:27
To:	EVERHART
Subj:	SHELL.COM (UNIX(TM)-style '>' and '<' for DCL)

Received: from CU20B.COLUMBIA.EDU by KL.SRI.COM with TCP; Fri 21 Aug 87 14:16:44-PDT
Date: Fri 21 Aug 87 17:14:47-EDT
From: Christopher P. Lent <OC.PEDHEM@CU20B.COLUMBIA.EDU>
Subject: SHELL.COM (UNIX(TM)-style '>' and '<' for DCL)
To: INFO-VAX@KL.SRI.COM
cc: OC.PEDHEM@CU20B.COLUMBIA.EDU
Message-ID: <12328340100.164.OC.PEDHEM@CU20B.COLUMBIA.EDU>

Hi,

	Here's a DCL .COM file which provides a quick way to
do UNIX(TM) style I/O redirection for the '>' and '<' operators.
We've used it since VMS 2.0 at Cooper Union with great success.

Chris Lent
OC.PEDHEM@CU20B.COLUMBIA.EDU
........................ Cut between dotted lines and save ..................
$!..........................................................................
$! VAX/VMS archive file created by VMS_SHAR V-4.03 05-Aug-1987
$! which was written by Michael Bednarek (U3369429@ucsvc.dn.mu.oz.au)
$! To unpack, simply save and execute (@) this file.
$!
$! This archive was created by LENT
$!      on Friday 21-AUG-1987 16:28:47.23
$!
$! It contains the following 2 files:
$! SHELL_README.TXT SHELL.COM
$!===========================================================================
$ Set Symbol/Scope=(NoLocal,NoGlobal)
$ Version=F$GetSYI("VERSION") ! See what VMS version we have here:
$ If Version.ges."V4.4" then goto Version_OK
$ Write SYS$Output "Sorry, you are running VMS ",Version, -
                ", but this procedure requires V4.4 or higher."
$ WRITE SYS$OUTPUT "But the files contained do not."
$ WRITE SYS$OUTPUT "You can remove SHELL_README.TXT and SHELL.COM"
$ WRITE SYS$OUTPUT "into two files by hand and then delete the "
$ WRITE SYS$OUTPUT "leading X's with the following EDT NOKEYPAD commands"
$ WRITE SYS$OUTPUT "$!  First edit the file:"
$ WRITE SYS$OUTPUT "$ EDIT /EDT SHELL.COM "
$ WRITE SYS$OUTPUT "*! Set the mode to HARDCOPY"
$ WRITE SYS$OUTPUT "*SET TERM HCPY"
$ WRITE SYS$OUTPUT "*! go to the top of the file"
$ WRITE SYS$OUTPUT "*1"
$ WRITE SYS$OUTPUT "*! Change to hardcopy nokeyad change mode"
$ WRITE SYS$OUTPUT "*CHANGE"
$ WRITE SYS$OUTPUT "C*1000(ADVDCL).
$ WRITE SYS$OUTPUT "C*EX"
$ WRITE SYS$OUTPUT "*!The End of Buffer will cause two errors. Ignore them."
$ WRITE SYS$OUTPUT "*! then use WRITE or EX to save the file."
$ WRITE SYS$OUTPUT "*! Sorry about all this work! [CPL]"
$ Exit 44
$Version_OK: CR[0,8]=13
$ Pass_or_Failed="failed!,passed."
$ Goto Start
$Convert_File:
$ Read/Time_Out=0/Error=No_Error1/Prompt="creating ''File_is'" SYS$Command ddd
$No_Error1: Define/User_Mode SYS$Output NL:
$ Edit/TPU/NoSection/NoDisplay/Command=SYS$Input/Output='File_is' -
        VMS_SHAR_DUMMY.DUMMY
f:=Get_Info(Command_Line,"File_Name");b:=Create_Buffer("",f);
o:=Get_Info(Command_Line,"Output_File");Set (Output_File,b,o);
Position (Beginning_of(b));Loop x:=Erase_Character(1); Loop ExitIf x<>"V";
Move_Vertical(1);x:=Erase_Character(1);Append_Line;Move_Horizontal
(-Current_Offset);EndLoop;Move_Vertical(1);ExitIf Mark(None)=End_of(b)
EndLoop;Exit;
$ Delete VMS_SHAR_DUMMY.DUMMY;*
$ Checksum 'File_is
$ Success=F$Element(Check_Sum_is.eq.CHECKSUM$CHECKSUM,",",Pass_or_Failed)+CR
$ Read/Time_Out=0/Error=No_Error2/Prompt=" CHECKSUM ''Success'" SYS$Command ddd
$No_Error2: Return
$Start:
$ File_is="SHELL_README.TXT"
$ Check_Sum_is=1964575735
$ Copy SYS$Input VMS_SHAR_DUMMY.DUMMY
XHi,
X        SHELL.COM is a simple .COM file which supports UNIX style I/O
Xredirection. For example, the following session demonstrates a simple
Xuse:
X        $ SHELL :== @SHELL.COM
X        $ SHELL
X        >> DIR >K.L
X        >> CREATE DIR.LIST <K.L
X        >> EXIT
X        $
X
X        The directory listing is put in the file K.L. Then
Xthe listing is used as standard input for the create command.
X
XRedirection of input:
X        The file specification following a '<' is assigned to
XSYS$INPUT for the duration of the command.
X
XRedirection of output:
X        The file specification following a '>' is assigned to
XSYS$OUTPUT for the duration of the command. Note that any error output
Xwritten to the file specified AND to the local terminal.
X
XLimitations:
X        SHELL does NOT support piping '|', appending '>>',
Xor shell input '<<'.
X
XPrompts:
X        The SHELL prompt is '>>'.  An alternate prompt may be specfied
Xas in the following example:
X
X                $ SHELL :== @SHELL.COM
X                $! Note: Quote the prompt if you do not want all UPPERCASE
X                $ SHELL "My_prompt"
X                My_prompt exit
X                $
X
XDefault file names:
X        Some programs will specify default extensions for SYS$OUTPUT.
XIn the following example, an output file called J.LIS; is created
Xrather than the J.; that might be expected.  To specify J. as the output
Xfile the '.' must be explicitly included.
X                $ SHELL :=== @SHELL.COM
X                >> dir >j
X                >> ! A J.LIS file results from the default naming
X                >> ! convention of the DIRECTORY program.
X                >> dir >j.
X                >> ! The '.' overrides the default file extension.
X                >> exit
X                $
X        As an aside, a few VMS system programs make it difficult to
Xwork with the file .; which is a legal, but strange, filename.
X
XText file formats:
X        Some VMS languages, such as FORTRAN, do not
Xopen SYS$OUTPUT in standard text file format in order to support
Xconcepts such as carriage control.  This functionality may upset
Xsubsequent programs which must read files of previously redirected output.
XAs VMS editors became more intelligent about handling
Xunusual file formats, this ceased to be a problem.
X
XAlternate terminal support:
X        The SPEC TERM TXXX: command and the SPEC RESET
Xperform a limited form of alternate terminal support.  Any command
Xtyped on the local terminal after a SPEC TERM TXA1: command, will
Xread PROGRAM input and write PROGRAM output to TXA1:.
X        To cancel a previous SPEC TERM TXXX:, use the SPEC RESET to restore
Xinput and output to SYS$COMMAND.
X        The SPEC TERM TXXX: command may be used in conjunction
Xwith the '>' and '<' operators.
X        Since VMS 3.0 and enhanced terminal security, the value
Xof SPEC TERM TXXX: has become questionable.
X
XDCL implications:
X        SHELL is transparent to the DCL command history mechanisms.
XBoth the RECALL/ALL command and the Line editing keys, can access
Xcommands entered before, during and after the SHELL session.
X
XUnwanted Feature:
X        SHELL has an undersirable feature of doubling any error output
Xsent to SYS$ERROR when output redirection is not done.
XThere are ways to stop this but we never got around to it.
X
XHistory:
X        SHELL was developed by Peters J. Vecrumba under VMS 2.0
Xand has worked without change with each VMS revision.
XAdditional modifications were added by Karl Siil and Chris Lent.
X
XRevisions and bugs:
X        Any revisions, bug reports and comments are welcome.
X        Please send them to me at any of the following addresses:
X
X        OC.PEDHEM@CU20B.COLUMBIA.EDU                 [ARPA]
X        PEDHEM@CUCCFA                                [BITNET]
X        cbosgd!philabs!phri!cooper!chris             [UUCP]
X          seismo!cmcl2!phri!cooper!chris             [UUCP]
X                 cmcl2!phri!cooper!chris             [UUCP]
X        Tel: (203) 452-1522 (Answering machine if I'm not there)
X
X
XEnjoy,
XChris Lent
XFri Aug 21 15:02:08 EST 1987
$ GoSub Convert_File
$ File_is="SHELL.COM"
$ Check_Sum_is=1702760346
$ Copy SYS$Input VMS_SHAR_DUMMY.DUMMY
X$! BUILD SHELL AROUND DCL
X$!
X$! Performs SIMPLE UNIX(TM) style I/O redirection:
X$! Supports: '>' and '<' operators
X$! Other features: type SPEC HELP
X$!
X$! Original VMS 2.0 Version by:
X$! Peters J. Vercrumba
X$!
X$! Modifications by:
X$! Karl Siil and
X$! Chris Lent  ihnp4!philabs!phri!cooper!chris          [UUCP]
X$!             OC.PEDHEM@CU20B.COLUMBIA.EDU             [ARPA/Internet]
X$!              PEDHEM@CUCCFA.BITNET                    [BITNET]
X$! Please send any bug reports, enchancments and comments to the
X$! preceding email address(es):
X$! Note: type EXIT to leave SHELL
X$! Optional feature:  Help on Control-Y (tells user to type exit)
X$!                      Activate by uncommenting line following
X$!                      [OPTIONAL1] comment.
X$! Version 6.2 Fri Aug 21 13:36:20 EST 1987
X$! Initializations:
X$               PROMPT := "''P1'"
X$               IF P1 .EQS. "" THEN PROMPT := ">>"
X$               SET NOON
X$               MY_TERM := 'F$LOGICAL("SYS$COMMAND")'
X$! Name of this procedure
X$               MY_NAME := "SHELL"
X$!
X$RESET:         ON CONTROL_Y THEN GOTO TRAP_Y
X$GET_LINE:      INQUIRE/NOPUNC TEXT "''PROMPT' "
X$               LINE := "''TEXT'"
X$               P0 := ""
X$               P1 := ""
X$               P2 := ""
X$               P3 := ""
X$               P4 := ""
X$               P5 := ""
X$               P6 := ""
X$               P7 := ""
X$               P8 := ""
X$               STO := ""
X$               STI := ""
X$               NARGS = 0
X$!
X$!      FIRST CHECK IF WE HAVE ANYTHING AT ALL
X$!
X$               IF LINE .EQS. "" THEN  -
X$                       !  NOTHING THERE -
X$                       GOTO GET_LINE
X$!
X$!      CHECK FOR STANDARD OUTPUT REASSIGNMENT
X$!
X$               KET = 'F$LOCATE(">",LINE)'
X$               LEN = 'F$LENGTH(LINE)'
X$               IF 'KET' .EQS. 'LEN' THEN  -
X$                       !  NO STANDARD OUTPUT REDIRECTION  -
X$                       GOTO NO_KET
X$               LEFT := 'F$EXTRACT(0,KET,LINE)'
X$               LEN = LEN - KET
X$               KET = KET + 1
X$               RIGHT := 'F$EXTRACT(KET,LEN,LINE)'
X$               SEP = 'F$LOCATE(" ",RIGHT)'
X$               LEN = 'F$LENGTH(RIGHT)'
X$               IF 'SEP' .EQS. 'LEN' THEN -
X$                       !  RIGHT PART IS OUTPUT, LEFT COMMAND -
X$                       GOTO RIGHT_STO
X$               STO := 'F$EXTRACT(0,SEP,RIGHT)'
X$               LEN = LEN - SEP
X$               SEP = SEP + 1
X$               RIGHT := 'F$EXTRACT(SEP,LEN,RIGHT)'
X$               GOTO FIN_STO
X$RIGHT_STO:     STO := 'RIGHT'
X$               RIGHT := ""
X$FIN_STO:       LINE := 'LEFT''RIGHT'
X$!
X$NO_KET:
X$!
X$!      CHECK FOR STANDARD INPUT REASSIGNMENT
X$!
X$               BRA = 'F$LOCATE("<",LINE)'
X$               LEN = 'F$LENGTH(LINE)'
X$               IF 'BRA' .EQS. 'LEN' THEN  -
X$                       !  NO STANDARD INPUT REDIRECTION  -
X$                       GOTO NO_BRA
X$               LEFT := 'F$EXTRACT(0,BRA,LINE)'
X$               LEN = LEN - BRA
X$               BRA = BRA + 1
X$               RIGHT := 'F$EXTRACT(BRA,LEN,LINE)'
X$               SEP = 'F$LOCATE(" ",RIGHT)'
X$               LEN = 'F$LENGTH(RIGHT)'
X$               IF 'SEP' .EQS. 'LEN' THEN -
X$                       !  RIGHT PART IS OUTPUT, LEFT COMMAND -
X$                       GOTO RIGHT_STI
X$               STI := 'F$EXTRACT(0,SEP,RIGHT)'
X$               LEN = LEN - SEP
X$               SEP = SEP + 1
X$               RIGHT := 'F$EXTRACT(SEP,LEN,RIGHT)'
X$               GOTO FIN_STI
X$RIGHT_STI:     STI := 'RIGHT'
X$               RIGHT := ""
X$FIN_STI:       LINE := 'LEFT''RIGHT'
X$!
X$NO_BRA:
X$!
X$GET_SEP:       SEP = 'F$LOCATE(" ",LINE)'
X$               LEN = 'F$LENGTH(LINE)'
X$               IF 'SEP' .NE. 'LEN' THEN -
X$                       ! STILL HAVE SEPERATORS -
X$                       GOTO HAVE_SEP
X$!              ELSE
X$                       P'NARGS' := 'LINE'
X$                       GOTO NOMORE_ARGS
X$HAVE_SEP:      P'NARGS' := 'F$EXTRACT(0,SEP,LINE)'
X$               LEN = LEN - SEP
X$               SEP = SEP + 1
X$               LINE := 'F$EXTRACT(SEP,LEN,LINE)'
X$               NARGS = NARGS + 1
X$               GOTO GET_SEP
X$!
X$NOMORE_ARGS:
X$!
X$DO_COMMAND:
X$!
X$               IF "''P0'" .EQS. "SPEC" THEN  -
X$                       !  SPECIAL MODE -
X$                       GOTO SPEC_MODE
X$!
X$               DEASSIGN SYS$INPUT
X$               DEASSIGN SYS$OUTPUT
X$               ASSIGN 'MY_TERM' SYS$INPUT
X$               ASSIGN 'MY_TERM' SYS$OUTPUT
X$               IF "''STO'" .EQS. "" THEN -
X$                       GOTO NO_STO
X$               DEASSIGN SYS$OUTPUT
X$               ASSIGN 'STO' SYS$OUTPUT
X$NO_STO:
X$               IF "''STI'" .EQS. "" THEN -
X$                       GOTO NO_STI
X$               DEASSIGN SYS$INPUT
X$               ASSIGN 'STI' SYS$INPUT
X$NO_STI:
X$               'P0' 'P1' 'P2' 'P3' 'P4' 'P5' 'P6' 'P7' 'P8'
X$!
X$FINI:
X$               DEASSIGN SYS$INPUT
X$               DEASSIGN SYS$OUTPUT
X$               ASSIGN 'MY_TERM' SYS$INPUT
X$               ASSIGN 'MY_TERM' SYS$OUTPUT
X$!
X$               GOTO GET_LINE
X$SPEC_MODE:
X$               IF "''P1'" .NES. "" THEN -
X$                       GOTO DO_SPEC_1
X$               INQUIRE/NOPUNC P1 ">_special:   "
X$               GOTO SPEC_MODE
X$!
X$DO_SPEC_1:     IF "''P1'" .NES. "TERM" THEN -
X$                       GOTO DO_SPEC_2
X$               IF "''P1'" .NES. "" THEN -
X$                       MY_TERM := 'P2'
X$               WRITE SYS$OUTPUT ">%terminal set to ''MY_TERM'"
X$               GOTO GET_LINE
X$DO_SPEC_2:     IF "''P1'" .NES. "RESET" THEN -
X$                       GOTO DO_SPEC_3
X$! reset terminal setting
X$               MY_TERM := 'F$LOGICAL("SYS$COMMAND")'
X$               WRITE SYS$COMMAND ">%terminal reset to ''MY_TERM'"
X$               GOTO GET_LINE
X$DO_SPEC_3:
X$ WRITE SYS$COMMAND ">Special modes are:"
X$ WRITE SYS$COMMAND "SPEC TERM [terminal]"
X$ WRITE SYS$COMMAND "     Execute following programs with input and"
X$ WRITE SYS$COMMAND "     output coming from and going to [terminal]."
X$ WRITE SYS$COMMAND "   Example: SPEC TERM TXA1:"
X$ WRITE SYS$COMMAND " "
X$ WRITE SYS$COMMAND "SPEC RESET"
X$ WRITE SYS$COMMAND "     Cancel a previous SPEC TERM command"
X$               GOTO GET_LINE
X$!
X$TRAP_Y:
X$!      DEASSIGN SYS$INPUT
X$!      DEASSIGN SYS$OUTPUT
X$!      ASSIGN 'MY_TERM' SYS$INPUT
X$!      ASSIGN 'MY_TERM' SYS$OUTPUT
X$!
X$! [OPTINAL1] Uncomment for help on Control-Y and Control-C
X$!WRITE SYS$COMMAND "%''MY_NAME'-I-CTRLY Type EXIT to leave ''MY_NAME'."
X$       GOTO RESET
X$! EOF
$ GoSub Convert_File
$ Exit
$! That's the end of the VMS DCL archive for SHELL_README.TXT and SHELL.COM
-------
