7.3.38 PIPE_CMD_LAST parameter (defines execution processing for the last command in a pipe)
Syntax
- UNIX edition
-
#-adsh_conf PIPE_CMD_LAST {CURRENT|OTHER}
- Windows Edition
-
#-adsh_conf PIPE_CMD_LAST {CURRENT|OTHER|SEQUENTIAL}
Description
This parameter specifies whether the last command in the pipeline in the current process is to be executed.
You specify CURRENT to update the contents of variables by using the last command in the pipeline and you want to use the updated contents in commands that follow the pipeline, as described in the following.
- Contents of job definition script:
typeset -i CNT=0 cat INFILE | while read STR do echo "$STR" let CNT=CNT+1 done echo "Line count is $CNT."
As a result, when the while statement terminates, the shell variable CNT stores the number of lines loaded by the read command (INFILE line count).
On the other hand, if you want use the last command in the pipeline to update the contents of variables but you want to revert to using the contents of the pre-update variables after the pipeline has terminated, specify OTHER (CBL_SYSUT1 and CBL_SYSUT2 are assumed to be common interface variables of CBLUAPx).
- Contents of job definition script:
CBL_SYSUT1=/file1 CBL_SYSUT2=/file2 CBLUAP1 cat INFILE | while read DIR do CBL_SYSUT1=`cmd1 y` CBL_SYSUT2=`cmd2 y` CBLUAP2 done CBLUAP3
In this case, when the while statement terminates, the shell variable CBL_SYSUT1 stores "/file1" and the shell variable CBL_SYSUT2 stores "/file2".
This parameter cannot be specified more than once in the same environment file. If it is specified more than once, an error message is output and the job terminates.
Operands
- CURRENT
All commands in the pipeline are asynchronously executed. Specifies that when the last command in the pipeline is one of the following, the command is to run in the current process:
Shell standard command
Substitution expression
Script control statement
-
Extended shell command
-
Reserved script command
-
Function
If the last command of the pipeline is other than above, the command operates in another process.
- OTHER
All commands in the pipeline are asynchronously executed.Specifies that the last command in the pipeline is to run in another process.
- SEQUENTIAL [Windows only]
-
This command sequentially executes all commands of the pipeline by the current process. In addition, a temporary file is used for exchanging data between commands.
This is the same behavior as that of Windows edition JP1/Advanced Shell 11-00 or earlier.
Notes
If this parameter is defined in both the system environment file and the job environment file, the definition in the job environment file takes effect.
-
If you specify OTHER or CURRENT in the Windows version, the execution time may be longer than when specifying SEQUENTIAL. Therefore, you must verify the execution time of a job when switching from SEQUENTIAL to OTHER or CURRENT.
Example
The examples below show the difference in the execution result when the input file and job definition script shown in the following are used to specify the PIPE_CMD_LAST parameter.
Example 1
Contents of job definition script:
STR="abcdefg" echo "ABCDEFG" | read STR echo $STR
Output result to the standard output (if CURRENT or SEQUENTIAL is specified for the PIPE_CMD_LAST parameter)
ABCDEFG
Result output to the standard output (when OTHER is specified in the PIPE_CMD_LAST parameter):
abcdefg
Example 2
Contents of job definition script:
A=1 echo "Hello World" | A=10 echo $A
Output result to the standard output (if CURRENT or SEQUENTIAL is specified for the PIPE_CMD_LAST parameter)
10
Result output to the standard output (when OTHER is specified in the PIPE_CMD_LAST parameter):
1
Example 3
Contents of the INFILE input file:
user1,500,Tomato user2,1000,Tomato user3,300,Lettuce user1,450,Cabbage user1,250,Orange
Contents of the job definition script:
typeset -i cnt=1 cat INFILE | grep user1 | while read NAME do if [ $cnt -ge 3 ]; then break fi echo "$cnt = $NAME" let cnt=cnt+1 done echo $cnt
The character strings from while to done are treated as the last command in the pipe.
Output result to the standard output (if CURRENT or SEQUENTIAL is specified for the PIPE_CMD_LAST parameter)
1 = user1,500,Tomato 2 = user1,450,Cabbage 3
Result output to the standard output (when OTHER is specified in the PIPE_CMD_LAST parameter):
1 = user1,500,Tomato 2 = user1,450,Cabbage 1