When creating redirection constructions it is important to remember
that the redirection specification is stripped from the command
line after string substitution (variable and expression
substitution) but before the command is actually executed.
For example, suppose you entered:
editor <myfile >$null newfile
|
With CIOR, this command works without problems because both
redirection specifications, <myfile and $null, are
removed from the command line before it is invoked. This
leaves:
Input, however, would be read from myfile and command output
would be sent to $null. An offline listing would go to
newfile however, because that's the function of this
parameter in the EDITOR subsystem.
To further illustrate how string substitution works, let's
revisit an example already used in this chapter which has a
command file with the following contents:
parm showdest="$stdlist"
showme
showout >!showdest
showvar
showjob >>!showdest ;job=!hpuser.!hpaccount
|
The default value for the showdest parameter is $stdlist in
this example. If the user does not enter a parameter the showout
command becomes
The redirection specification is stripped from the command line and
no redirection is done because none is necessary. $STDIN behaves
similarly. (In fact the capability to specify >$STDLIST and
<$STDIN as redirection specifications is provided to
handle this type of defaulting).
But this example also illustrates why the scan for redirection
specifications is done after string substitution. If the redirection scan were done before string substitution, or at
the same time, the user couldn't specify an input or output
redirection file using parameters or variables as in the
last example. This ordering always allows the following:
setvar dest ">abc"
listf !dest
|
Because string substitution occurs first listf becomes
listf >abc and then redirection sends the output to file abc.
Expression substitution is also done in the string substitution pass
and would, therefore, also be performed before the redirection scan.
For example, the LISTF command might be invoked as follows:
listsf ![input('ENTER THE FILESET TO BE DISPLAYED:')],6 &
>![input('ENTER THE FILE NAME FOR THE OUTPUT OF THE LISTF:')]
|
During the string substitution scan the user is prompted first
for the file set, and then for the output file name. If the user entered abc@ef and then outfile the command line would be
the following after the string substitution pass:
Next, the output would be redirected and then the listf would
be invoked.