5.1.6 Metacharacters
Metacharacters are characters that have special meaning in job definition scripts. If you include any of the following characters in a job definition script, the job controller interprets it as a metacharacter:
|, &, ;, <, >, (, ), $, `, ', \, ", ~, #, *, [, ], ?
If you want to use a metacharacter as a normal character, you must invalidate its metacharacter usage. The following table explains how to invalidate metacharacters.
Invalidation method |
Description |
---|---|
'str' |
The character string str processes all characters other than the single quotation mark (') as normal characters. |
"str" |
The character string str processes all characters other than the dollar sign ($), backslash (\), and grave accent mark (`) as normal characters. However, if \ is immediately followed by $, \, `, or ", then \ is treated as a metacharacter. To include \ as a normal character in the character string str, specify \\. |
\char |
Invalidates (escapes) the special meaning of the characters char. |
When invalidated metacharacters are output, the output processing depends on the specifications of the built-in command used, such as the echo and print commands.
- Contents of job definition script:
echo 'JP1/AS\n' # 1. echo "JP1/AS\n" # 2. echo JP1/AS\\n # 3. echo 'JP1/AS\\n' # 4. echo "JP1/AS\\n" # 5.
- STDOUT file contents of the executed job:
******** JOB SCOPE STDOUT ******** JP1/AS
As a result of 1, the echo command outputs \n as a line break. JP1/AS
Result of 2 JP1/AS
Result of 3 JP1/AS\n
As a result of 4, \ is treated as an escape character and \n is output as distinct characters. JP1/AS
Result of 5
In 4, because the characters are enclosed by single quotation marks ('), \\n is passed to the echo command. As a result, the echo command interprets \\ as the character \, and outputs the characters \ and n.
In 5, because the characters are enclosed by double quotation marks ("), \\ is interpreted as the character \, and \n is passed to the echo command. As a result, the echo command outputs \n as a linefeed code.
The following subsections explain functions using metacharacters.
- Organization of this subsection
(1) Positional parameters
When you execute a job definition script, you can pass parameters to the job definition script as arguments by specifying run-time parameters following the job definition script file name. JP1/Advanced Shell assigns these arguments to special variables called positional parameters. There are 10 positional parameters, $0 through $9. The file name of the executed job definition script is assigned to $0, and arguments are assigned to $1 through $9 in the order specified. The following table lists and describes the positional parameters of JP1/Advanced Shell and the related special characters.
Positional parameter or special character |
Description |
|
---|---|---|
Positional parameters |
$0 |
File name of the job definition script. |
$n |
Value of argument n specified in the job definition script (n: 1 through 9) |
|
Related special characters |
$# |
Number of arguments specified in the job definition script |
$* |
All arguments specified in the job definition script |
|
$@ |
All arguments specified in the job definition script |
|
"$*" |
Handles all arguments specified in the job definition script as a group. Example: "$1 $2 $3 ... " If the value of the IFS shell variable has been changed, the values are delimited by the new value of the IFS shell variable. |
|
"$@" |
Handles the arguments specified in the job definition script individually. Example: "$1" "$2" ... " If the IFS shell variable has been changed, the values are delimited by the space. |
You use the set standard shell command to change the positional parameters in a job definition script. For details about the set command, see 9.3.23 set command (sets shell options, creates an array, or displays variable values) in 9.3 Standard shell commands.
(2) String separators
In JP1/Advanced Shell, the characters specified in the IFS shell variable are treated as string separators. The space and tab characters are treated as string separators because the initial values of the IFS shell variable are the space, tab, and end-of-line characters. Any number of consecutive spaces and tab characters are treated as a single separator. For details about the IFS shell variable, see 5.5 Shell variables.
To use space or tab characters in character strings, you must enclose the character string containing the space or tab character in quotation marks (' or ").
(3) Line continuation
The following explains how to specify a command over multiple lines:
Specify a backslash (\) at the end of a line that is to continue onto the next line.
Enclose the entire multi-line specification in a single set of quotation marks (but do not specify a quotation mark at the end of each line that is continued onto the next line).
JP1/Advanced Shell treats such a set of lines as continued lines and processes them as a single line.
(4) Comments
You can specify comments in job definition scripts. When a hash mark (#) is specified in a line, the rest of the line from the hash mark through the end of the line is treated as a comment. However, if a hash mark is followed by -adsh, the line is processed as follows:
Line that begins with #-adsh
This line is treated as an extended script command.
Specification of #-adsh continues onto the next line
The continuation line is treated as a comment line. The following shows an example:
echo ABC \ #-adsh
However, anytime #-adsh is not continued from the previous line or is not at the beginning of a line, an error results.
Coding other than #-adsh is specified
The line is treated as a comment line.
Note that a comment cannot be specified on a line that contains an extended script command.
(5) Wildcards
You can use wildcard characters to obtain file names and directory names that satisfy specified conditions and to compare such names with desired character strings.
The following table describes the wildcard characters supported in JP1/Advanced Shell.
Wildcard character |
Description |
---|---|
? |
Matches any single character, except the dot (.) in dot files. |
* |
Matches a character string consisting of any number of characters, except the dot (.) in dot files. |
[...] |
Match is based on the character string enclosed in the square brackets ([]). When ! is specified at the beginning of the character string enclosed in the square brackets, the wildcard matches any character string other than the character string that is enclosed in the square brackets. To specify ] as a character, specify it at the beginning of the character string. If two characters are separated by a hyphen (-), the match is of any character between those two characters (including the two characters themselves). To specify the hyphen (-) as a character, specify it at the beginning or end of the character string. The following table shows an example. |
{str,...} |
Expands the str strings delimited by the comma by using brace expansion. This expansion is not performed in the following cases:
|
The following table shows example specifications of the square brackets wildcard ([]).
Specification example |
Description |
---|---|
[]a] |
Matches the character string ]a. |
[!abc] |
Matches any character string other than abc. |
[0-9] |
Matches one of the numbers from 0 through 9. |
[a-z] |
Matches any lowercase letter. |
[A-Z] |
Matches any uppercase letter. |
[0-9a-zA-Z] |
Matches any alphanumeric character. |
[-abc] |
Matches the character string -abc. |
[!-abc] |
Matches any character string other than -abc. |
(6) Substitution
The following three substitution functions are available:
Variable substitution
Replaces a variable's status, the length (in bytes) of a character string constituting the value of a variable, the number of elements in an array variable, or the value of a variable expanded by matching the variable value and a specified pattern.
Command substitution
Treats a command's standard output as a variable value.
File name substitution
Expands a file name that matches a specified condition by using wildcard characters, such as * and ?. Note that if the noglob shell option is enabled, file names are not replaced. For details about the noglob shell option, see 5.6.1 Shell options that can be specified with the set command.
(a) Variable substitution
Variable substitution includes substitution of a variable based on the status of the variable, substitution of a variable for the length of a character string constituting the value of a variable or for the number of elements in an array, substitution of a variable based on the result of pattern matching, and substring expansion.
Variable substitution depending on the status of the variable
The table below lists and describes the formats used to perform variable substitution depending on the status of the variable. In these formats, variable represents a variable name and word represents the variable that is expanded according to the status of variable. In the examples and results, a indicates an undefined variable, b=NULL, and c=1.
Table 5‒10: Formats used to perform variable substitution depending on the status of the variable Format
Description
Examples
Results
${variable:-word}
If variable is defined as a variable and a value is assigned to it, the value of variable is returned. If variable is defined but its value is NULL or undefined, the expansion result of word is returned. The value of variable remains unchanged.
cnt=${a:-7}
7 is assigned to cnt.
cnt=${b:-8}
8 is assigned to cnt.
cnt=${c:-9}
Value of c is assigned to cnt.
${variable-word}
If variable is defined as a variable and a value is assigned to it, the value of variable is returned. If variable is defined and its value is NULL, the value of variable (NULL) is returned. If variable is undefined, the expansion result of word is returned. The value of variable remains unchanged.
cnt=${a-7}
7 is assigned to cnt.
cnt=${b-8}
NULL is assigned to cnt.
cnt=${c-9}
Value of c is assigned to cnt.
${variable:=word}
If variable is defined as a variable and a value is assigned to it, the value of variable is returned. If variable is defined and its value is NULL or undefined, the expansion result of word is assigned to variable, and then the value of variable is returned. Note that this format is applicable only to variables, not to positional parameters.
cnt=${a:=7}
7 is assigned to a and the value of a is assigned to cnt.
cnt=${b:=8}
8 is assigned to b and the value of b is assigned to cnt.
cnt=${c:=9}
Value of c is assigned to cnt.
${variable=word}
If variable is defined as a variable and a value is assigned to it, the value of variable is returned. If variable is defined and its value is NULL, the value of variable (NULL) is returned. If variable is undefined, the expansion result of word is assigned to variable, and then the value of variable is returned. Note that this format is applicable only to variables, not to positional parameters.
cnt=${a=7}
7 is assigned to cnt.
cnt=${b=8}
NULL is assigned to cnt.
cnt=${c=9}
Value of c is assigned to cnt.
${variable:?[word]}
If variable is defined as a variable and a value is assigned to it, the value of variable is returned.
If word is specified and variable is defined and its value is NULL or undefined, the expansion result of word is output to the standard error output, and then the job definition script is terminated.
If word is omitted and variable is defined and its value is NULL or undefined, the KNAX6050-E message indicating that variable is undefined is issued, and then the job definition script is terminated.
The value of variable remains unchanged.
cnt=${a:?7}
The expansion result is output to the standard error output, and then the shell is terminated.
cnt=${a:?}
A message is output, and then the shell is terminated.
cnt=${b:?8}
The expansion result is output to the standard error output, and then the shell is terminated.
cnt=${c:?9}
Value of c is assigned to cnt.
${variable?[word]}
If variable is defined as a variable and a value is assigned to it, the value of variable is returned.
If word is specified and variable is undefined, the expansion result of word is output to the standard error output, and then the job definition script is terminated.
If word is omitted and variable is undefined, the KNAX6050-E message indicating that variable is undefined is issued, and then the job definition script is terminated.
The value of variable remains unchanged.
cnt=${a?7}
The expansion result is output to the standard error output, and then the shell is terminated.
cnt=${a?}
A message is output, and then the shell is terminated.
cnt=${b?8}
NULL is assigned to cnt
cnt=${c?9}
Value of c is assigned to cnt. Value of c is assigned to cnt.
${variable:+word}
If variable is defined as a variable and a value is assigned to it, the expansion result of word is returned. Otherwise, NULL is returned. The value of variable remains unchanged.
cnt=${a:+7}
NULL is assigned to cnt.
cnt=${b:+8}
NULL is assigned to cnt.
cnt=${c:+9}
9 is assigned to cnt.
${variable+word}
If variable is defined as a variable and a value is assigned to it or the value is NULL, the expansion result of word is returned. Otherwise, NULL is returned. The value of variable remains unchanged.
cnt=${a+7}
NULL is assigned to cnt.
cnt=${b+8}
8 is assigned to cnt.
cnt=${c+9}
9 is assigned to cnt.
Variable substitution to the length of the character string constituting the value of the variable or to the number of array elements
The table below lists and describes the formats used to perform variable substitution to the length of the character string constituting the value of the variable or to the number of array elements. In these formats, variable represents a variable name and array represents an array name.
Table 5‒11: Formats used to perform variable substitution to the length of the character string constituting the value of the variable or to the number of array elements Format
Description
${#variable}
If variable is * or @, the variable is replaced with the number of positional parameters. Otherwise, the variable is replaced according to the setting specified for the VAR_SHELL_GETLENGTH environment setting parameter:
BYTE
Replaces the length of the value stored in variable with the number of bytes.
CHARACTER
Replaces the length of the value stored in variable with the number of characters.
If the VAR_SHELL_GETLENGTH environment setting parameter is not specified, the operation is the same as when BYTE is specified in the VAR_SHELL_GETLENGTH environment setting parameter.
${#array[*]}
The value is replaced with the number of elements of the array specified by array.
${#array[@]}
${#array[n][*]}
Replace with the number of elements of the line of the array specified with array[n][*].
${#array[n][@]}
Replace with the number of elements of the line of the array specified with array[n][@].
${#array[*][m]}
Replace with the number of elements of the column of the array specified with array[*][m].
${#array[@][m]}
Replace with the number of elements of the column of the array specified with array[@][m].
${#array[*][*]}
Replace with the number of elements of the array specified with array.
${#array[@][@]}
${?MAX:array}
Replace with the maximum number of lines of the array (one-dimensional array) and the maximum number of columns of the array (two-dimensional array) specified with array.
-
Usage example of the ${#array[*]} format
ARRAY=(a b c d e f g h i j k l m n o) echo ${#ARRAY[*]}
-->15
-
Usage example of the ${#array[n][*]} format
ARRAY[]=({ a b c d e } { f g h i j } { k l m n o }) echo ${#ARRAY[1][*]}
-->5
-
Usage example of the ${#array[*][m]} format
ARRAY[]=({ a b c d e } { f g h i j } { k l m n o }) echo ${#ARRAY[*][1]}
-->3
-
Usage example of the ${#array[*][*]} format
ARRAY[]=({ a b c d e } { f g h i j } { k l m n o }) echo ${#ARRAY[*][*]}
-->15
-
Usage example of the ${?MAX:array} format
ARRAY[]=({ a1 a2 a3 a4 a5 } { b1 b2 b3 b4 b5 } { c1 c2 c3 c4 c5 } \ { d1 d2 d3 d4 d5 } { e1 e2 e3 e4 e5 } { f1 f2 f3 f4 f5 } \ { g1 g2 g3 g4 g5 } { h1 h2 h3 } { i1 i2 i3 i4 }) unset ARRAY[2][3] ARRAY[2][5]=c6 echo ${?MAX:ARRAY}
-->9 6
n#1
m#2
0
1
2
3
4
5
0
a1
a2
a3
a4
a5
-
1
b1
b2
b3
b4
b5
-
2
c1
c2
-
c4
c5
c6
3
d1
d2
d3
d4
d5
-
4
e1
e2
e3
e4
e5
-
5
f1
f2
f3
f4
f5
-
6
g1
g2
g3
g4
g5
-
7
h1
h2
h3
-
-
-
8
i1
i2
i3
-
-
-
#1:
This value indicates a one-dimensional array element.
#2:
This value indicates a two-dimensional array element.
Variable substitution based on the result of pattern matching
The table below lists and describes the formats used to perform variable substitution based on the result of pattern matching. In these formats, variable represents a variable name and pattern represents a character string used to perform pattern matching with variable. Wildcard characters can be used in pattern.
Table 5‒12: Formats used to perform variable substitution based on the result of pattern matching Classification
Format
Description
Leading match
${variable#pattern }
If pattern matches the leading part of the variable value, the value in variable is replaced with its value less the shortest matching part (the shortest-matching part is deleted). Otherwise, the variable is replaced with the value of variable.
${variable##pattern }
If pattern matches the leading part of the variable value, the variable is replaced with its value less the longest matching part (the longest-matching part is deleted). Otherwise, the variable is replaced with the value of variable.
Trailing match
${variable%pattern }
If pattern matches the trailing part of the variable value, the variable is replaced with its value less the shortest matching part (the shortest-matching part is deleted). Otherwise, the variable is replaced with the value of variable.
${variable%%pattern }
If pattern matches the trailing part of the variable value, the variable is replaced with its value less the longest matching part (the longest-matching part is deleted). Otherwise, the variable is replaced with the value of variable.
The following shows an example of outputting a variable value with deletion of a specified character string (leading match).
Contents of the job definition script:
abc=abcd1234xyz987abcd1234efg echo ${abc#abcd} # 1. echo ${abc#a*2} # 2. echo ${abc##a*2} # 3. echo ${abc#*1234} # 4. echo ${abc##*1234} # 5. echo ${abc#1234} # 6.
STDOUT file contents of the executed job:
******** JOB SCOPE STDOUT ******** 1234xyz987abcd1234efg
Result of 1: The leading character string abcd is deleted. 34xyz987abcd1234efg
Result of 2: The string of characters from a through 2 is deleted (shortest match). 34efg
Result of 3: The string of characters from a through 2 is deleted (longest match). xyz987abcd1234efg
Result of 4: The string of characters from the beginning through 1234 is deleted (shortest match). efg
Result of 5: The string of characters from the beginning through 1234 is deleted (longest match). abcd1234xyz987abcd1234efg
Result of 6:The value of abc is output because there is no leading match.
The following shows an example of outputting a variable value with deletion of a specified character string (trailing match).
Contents of the job definition script:
abc=abcd1234xyz987abcd1234 echo ${abc%1234} # 1. echo ${abc%d*4} # 2. echo ${abc%%d*4} # 3. echo ${abc%34*} # 4. echo ${abc%%34*} # 5. echo ${abc%abcd} # 6.
STDOUT file contents of the executed job:
******** JOB SCOPE STDOUT ******** abcd1234xyz987abcd
Result of 1: The trailing character string 1234 is deleted. abcd1234xyz987abc
Result of 2: The trailing character string from d through 4 is deleted (shortest match). abc
Result of 3: The trailing character string from d through 4 is deleted (longest match). abcd1234xyz987abcd12
Result of 4: The character string beginning with 34 is deleted (shortest match). abcd12
Result of 5: The character string beginning with 34 is deleted (longest match). abcd1234xyz987abcd1234
Result of 6: The value of abc is output because there is no trailing match.
Substring expansion
The following table lists and describes the formats for variable substitution that is performed based on the result of substring expansion.
Table 5‒13: Formats for substring expansion Format
Description
${variable:offset}
Retrieves characters from the expansion result of variable. offset specifies the start position of the characters to be retrieved.
${variable:offset:length}
Retrieves as many characters as there are in maximum length from the expansion result of variable. offset specifies the start position of the characters to be retrieved.
${array[*]:offset}
Retrieves elements that begin with ${array[offset]} of the array.
${array[*]:offset:length}
Retrieves as many elements as there are in length that begin with ${array[offset]} of the array.
${array[@]:offset}
Retrieves elements that begin with ${array[offset]} of the array.
${array[@]:offset:length}
Retrieves as many elements as there are in length that begin with ${array[offset]} of the array.
${array[*][m]:offset}
Extract the element of column m beginning with the ${array[offset][m]} of the array.
${array[*][m]:offset:length}
Extract the element of column m beginning with ${array[offset][m]} of the array for the number of length.
${array[n][*]:offset}
Extract the element of the line beginning with ${array[n][offset]} of the array.
${array[n][*]:offset:length}
Extract the element of the line beginning with ${array[n][offset]} of the array for the number of length.
${array[@][m]:offset}
Extract the element of column m beginning with the ${array[offset][m]} of the array.
${array[@][m]:offset:length}
Extract the element of column m beginning with ${array[offset][m]} of the array for the number of length.
${array[n][@]:offset}
Extract the element of the line beginning with ${array[n][offset]} of the array.
${array[n][@]:offset:length}
Extract the element of the line beginning with ${array[n][offset]} of the array for the number of length.
${array[*][*]:offset}
Extract the element beginning with ${array[offset]} of the array.
${array[*][*]:offset:length}
Extract the element beginning with ${array[offset]} of the array for the number of length.
${array[@][@]:offset}
Extract the element beginning with ${array[offset]} of the array.
${array[@][@]:offset:length}
Extract the element beginning with ${array[offset]} of the array for the number of length.
- Legend:
variable: Specifies a variable name.
array: Specifies an array name.
offset: Specifies the start position in the character string or array element subject to partial expansion.
length: Specifies the number of characters or array elements to be expanded.
n: This letter specifies the line of a two-dimensional array.
m: This letter specifies the column of a two-dimensional array.
-
Usage example of the ${array[*]:offset} format
ARRAY=(a b c d e f g h i j k l m n o) echo ${ARRAY[*]:3}
-->d e f g h i j k l m n o
-
Usage example of the ${array[*]:offset:length} format
ARRAY=(a b c d e f g h i j k l m n o) echo ${ARRAY[*]:3:3}
-->d e f
-
Usage example of the ${array[*][m]:offset} format
ARRAY[]=({ a b c d e } { f g h i j } { k l m n o } { p q r s t }) echo ${ARRAY[*][1]:1}
-->g l q
-
Usage example of the ${array[*][m]:offset:length} format
ARRAY[]=({ a b c d e } { f g h i j } { k l m n o } { p q r s t }) echo ${ARRAY[*][1]:1:2}
-->g l
-
Usage example of the ${array[n][*]:offset} format
ARRAY[]=({ a b c d e } { f g h i j } { k l m n o } { p q r s t }) echo ${ARRAY[1][*]:1}
-->g h i j
-
Usage example of the ${array[n][*]:offset:length} format
ARRAY[]=({ a b c d e } { f g h i j } { k l m n o } { p q r s t }) echo ${ARRAY[1][*]:1:2}
-->g h
-
Usage example of the ${array[*][*]:offset} format
ARRAY[]=({ a b c d e } { f g h i j } { k l m n o } { p q r s t }) echo ${ARRAY[*][*]:3}
-->d e f g h i j k l m n o p q r s t
-
Usage example of the ${array[*][*]:offset:length} format
ARRAY[]=({ a b c d e } { f g h i j } { k l m n o } { p q r s t }) echo ${ARRAY[*][*]:3:3}
-->d e f
(b) Command substitution
The table below lists and describes the formats used to perform command substitution. In these formats, command represents the name of the command and the arguments to be executed.
In Windows, command substitution is executed by the current process excluding external commands when CURRENT is specified for the CMDSUB_PROCESS parameter (the default value is CURRENT).
Format name |
Format |
Description |
---|---|---|
$( ) format |
$(command) |
If the character string of command contains a backslash (\), \ has no special meaning. |
Grave character format |
`command` |
If the character string of command contains \, \ has a special meaning. To specify one command substitution within another, specify \ immediately before the inner grave accent mark character string such as `command \`command\``. |
In the grave character format, a backslash (\) in the character string of command is treated as a metacharacter. Therefore, if the character string of command contains \, the execution results differ between the $( ) and the grave character formats. We recommend that you use the $( ) format.
The following shows example specifications and execution results.
$( ) format
Specification example:
VAL=$(echo '\$x')
Result (value substituted in result)
\$x
Grave character format
Specification example:
VAL=`echo '\$x'`
Result (value substituted in result)
$x
Command substitution uses a temporary file for exchanging data under the following conditions:
-
In Windows
If CURRENT is specified for the CMDSUB_PROCESS parameter (default value).
-
In UNIX
If command substitution is executed for only a single command group connected with a pipe (|) in an environment where CURRENT has been specified for the COMPATIBLE_CMDSUB parameter and the PIPE_CMD_LAST parameter at the same time.
Example:
-
For the following process, data that is output to the standard output with cmd2 is output to a temporary file and then loaded into the job definition script as a character string:
`cmd1 | cmd2`
-
For the following process, a temporary file is not created as there are two command groups:
`cmd1 | cmd2; cmd3 | cmd4`
The temporary file is created in the location specified with the TEMP_FILE_DIR environment setting parameter.
-
For details regarding the CMDSUB_PROCESS parameter, see 7. Parameters Specified in the Environment Files > 7.3.11 CMDSUB_PROCESS parameter (defines the execution process of command substitution) [only for Windows].
For details regarding the COMPATIBLE_CMDSUB parameter, see 7. Parameters Specified in the Environment Files >7.3.14 COMPATIBLE_CMDSUB parameter (defines the behavior of command substitution) [only for UNIX].
(c) File name substitution
The table below lists and describes the formats used to perform file name substitution. In these formats, pattern represents a character string used for pattern matching. Wildcard characters can be used in pattern.
Format |
Description |
Example |
Matching character string |
---|---|---|---|
?(pattern|pattern ...) |
Matches one of the character strings specified as pattern. |
?(h) |
Null character string, h |
*(pattern|pattern ...) |
Matches none or any number of the character strings specified as pattern. |
*(h) |
Null character string, h, h, hh, hhh, ... |
+(pattern|pattern ...) |
Matches at least one of the character strings specified as pattern. |
+(h) |
h, hh, hhh, ... |
@(pattern|pattern ..) |
Matches only one of the character strings specified as pattern. |
@(h) |
h |
!(pattern|pattern ...) |
Matches all but one of the character strings specified as pattern. |
!(h) |
Any character string without h |
You can replace file names by specifying multiple patterns delimited by the vertical bar (|). Do not specify any spaces before or after the vertical bar delimiter. If there is such a space, it will be regarded as part of the pattern.
The following shows examples.
- Example of file name substitution
- Contents of job definition script:
ls -C # 1. Display the file in the current directory ls -C ?(*.sh|*.exe|*.dot) # 2. Display the file names whose extension is sh,exec, or dot ls -C *(*.sh|*.exe) # 3. Display the file names whose extension is either sh or exe ls -C +(*.jhs|*h) # 4. Display the file names whose extension is jhs or that end with h ls -C @(*.c|*.jhs) # 5. Display the file names whose extension is c or jhs ls -C !(*.c|*.jhs) # 6. Display the file names whose extension is neither c nor jhs
- STDOUT file contents of the executed job:
-
******** JOB SCOPE STDOUT ******** a.jhs a.sh a.txt func.c
Execution result of 1 a.sh
Execution result of 2 a.sh
Execution result of 3 a.jhs a.sh
Execution result of 4 a.jhs func.c
Execution result of 5 a.sh a.txt
Execution result of 6
File names beginning with a dot (.) are excluded as targets of pattern matching. To include file names beginning with a dot as targets of pattern matching, you must specify the dot explicitly.
(7) Arithmetic expansion
Arithmetic expansion involves performing an arithmetic operation and then assigning the result to a variable. The following shows the format and an example of arithmetic expansion.
$((arithmetic-expression))
- Example of arithmetic expansion:
- Contents of job definition script:
x=100 # 1. Value 100 is assigned to variable x x=$((x-1)) # 2. Perform the arithmetic operation and then assign the result to x echo $x # 3. Output the value of x to the standard output
- STDOUT file contents of the executed job:
******** JOB SCOPE STDOUT ******** 99 ... Value 99 is assigned to x.
(8) Input and output redirection
In job definition scripts, you can change the output destination of command execution results and the input source of information needed for command execution before commands are executed. These capabilities are called input and output redirection. This subsection explains input and output redirection as supported by JP1/Advanced Shell.
(a) Redirection
The table below describes the redirection methods supported by JP1/Advanced Shell. A redirection is interpreted from left to right.
Redirection |
Description |
---|---|
> file |
Uses file as the standard output. If file does not exist, the file is created. If file already exists, the existing file is overwritten.#1 |
< file |
Uses file as the standard input.#1 |
command_1 | command_2 |
This is a pipe. It uses the standard output of command_1 as the standard input for command_2. |
>>file |
Uses file as the standard output. If file does not exist, the file is created. If file already exists, new data is added to the existing file.#1 |
>|file |
Uses file as the standard output. If file does not exist, the file is created. If file already exists, the existing file is overwritten.#1 |
<>file |
Opens file as the standard input for read and write operations.#1 |
<<label |
This is a here document. |
n>file |
Redirects the output destination of file descriptor n to file.#1 |
n<file |
Inputs file descriptor n from file.#1 |
>&n |
Copies the standard output to file descriptor n. |
<&n |
Copies the standard input from file descriptor n. |
>&- |
Closes the standard output. |
<&- |
Closes the standard input. |
| |
Start the background process accompanying input and output from the parent process. |
>&p#3 |
Output destination of command is redirected to the background process. |
<&p#3 |
Input into the command is redirected to the background process. |
- #1:
-
If symbolic link is specified for file, link destination becomes target of input and output. If you specify the symbolic link without the link destination for redirection (>, >>, >|, <>) for output, behavior varies between UNIX edition and Windows edition.
UNIX edition
A file is created in the link destination.
Windows edition
For the symbolic link for file, a file is created in the link destination. For the symbolic link for directory, creation of a file fails.
- #2:
If |& is used to start multiple background processes that involve input and output operations from parent processes, the KNAX6029-E message might be issued and the job definition script might terminate with an error. Therefore, when you use |&, use a command such as wait to prevent multiple background processes from being started concurrently.
- #3:
-
In the UNIX edition, multiple background processes can be started by reassigning input into the background process to a different file descriptor. In the Windows edition, not less than 2 background processes cannot be started even if input into the background process to a different file descriptor.
(b) File descriptors
The following table lists and describes the file descriptors used by the job controller of JP1/Advanced Shell by input and output type.
Input or output type |
File descriptor |
Remarks |
---|---|---|
Standard input |
0 |
-- |
Standard output |
1 |
In the following circumstances, a job inherits the standard output that was in effect when the job controller process started:
In all other circumstances, a terminal is not opened by this file descriptor because the job controller uses standard output for output from the spool to STDOUT (stdout). |
Standard error |
2 |
In the following circumstance, a job inherits the standard error output that was in effect when the job controller process started:
In all other circumstances, a terminal is not opened by this file descriptor because the job controller uses standard output for output from the spool to STDERR (stderr). |
Other |
3 through 9 |
The user can use these file descriptors in job definition scripts. |
- Legend:
--: None
(c) Here document
A here document refers to creation of the standard input within the job definition script. The following table lists and describes the formats related to here documents.
Format |
Description |
---|---|
<< label document label |
The document part enclosed by label and label is passed to the standard input. A variable specified for document is replaced and spaces and tab characters are passed as is to the standard input. |
<<- label document label |
The document part enclosed by label and label is passed to the standard input. A variable specified for document is replaced and spaces are passed as is to the standard input. The tab character at the beginning of each line is deleted. |
<< \label document label |
The document part enclosed by label and label is passed to the standard input. A variable specified for document is not replaced. |
<< 'label' document label |
(d) Pipes
When you want to connect multiple commands and use the standard output from one command as the standard input to another, you can use pipes to connect the commands. A set of commands connected by a pipe is called a pipeline.
Processing of a pipeline is executed from left to right. The PIPE_CMD_LAST parameter can be sued to define whether the last command is to be executed in the current process# or as a separate process. The default setting is for execution in the current process.
- #
-
This is not applicable to commands executed as a separate processes (external commands, child jobs, UNIX-compatible commands, shell operation commands, sub-shells, background-specified commands, and background process-specified commands).
In Windows
The commands in a pipeline are executed sequentially, and temporary files are used to transfer data between commands. Also, the temporary files are created in the directory that is specified with the TEMP_FILE_DIR environment setting parameter. The PIPE_CMD_LAST parameter can be used to define whether the commands of the pipeline are to be executed as separate processes.
If the output command outputs data to the pipe in a state where the input command has ended and there are no processes, the output command will end in an error.
In UNIX
Commands in a pipeline will be executed as separate processes.
Also in UNIX, if multiple commands are connected by a pipe and then the output command outputs data to the pipe after the input command has terminated and while there is no process, the output command might receive SIGPIPE.
In the job controller, the command issues the message KNAX6522-E and terminates with an error, except when handling SIGPIPE.
For details regarding the PIP_CMD_LAST parameter, see 7. Parameters Specified in the Environment Files > 7.3.38 PIPE_CMD_LAST parameter (defines execution processing for the last command in a pipe).
(9) Command separators
Command separators enable you to specify multiple commands on a single line of a job definition script. The following table lists and describes the formats for command separators.
Format |
Description |
---|---|
command; |
The specification up to the semicolon (;) is interpreted as a command and its arguments. |
command_1 |
This is the AND control operator. If the left-hand command terminates with return code 0, the right-hand command is executed. |
command_1 |
This is the OR control operator. If the left-hand command terminates with any non-zero return code, the right-hand command is executed. |
The command separators can be used to handle and execute a group of commands as a single command group.
(10) Grouping commands
You can execute multiple commands in a batch by grouping them. You can also group multiple command groups. The following table lists and describes the formats for grouping commands.
Format |
Description |
---|---|
(command _1; |
Execute the command that is grouped in another process. A change made by another process is not inherited to the current process. The commands to be grouped are delimited by semicolons or line breaks. |
(command_1 (end-of-line) command_2 (end-of-line) ... ) |
|
{ |
Execute the command that is grouped in the current process. If you change the environment while you execute the command, a change is inherited after the command finishes. The commands to be grouped are delimited by semicolons or line breaks. For this format, insert at least one space after a left angle bracket ({) and insert a semicolon (;) or line break after the last command. |
{ command_2 (end-of-line) ...(end-of-line) } |
(11) Other metacharacters
The following table lists and describes the other metacharacters that are supported.
Metacharacter |
Description |
---|---|
~#1 |
Replaced with the HOME shell variable.#2 |
~any-character-string |
(UNIX only) Checks whether the user name matching the character string up to / or an argument delimiter is registered in the /etc/passwd file. If the user name is registered, this metacharacter is replaced with the corresponding user's login directory. If the user name is not registered, the specified character string is interpreted as a character string as is. |
~+#1 |
Replaced with the PWD shell variable. |
~-#1 |
Replaced with the OLDPWD shell variable. |
& |
Executes the job definition script or function in the background. |
- #1
The characters ~, ~+, and ~- are not replaced with the corresponding shell variables if they are enclosed in quotation marks or specified immediately before an escape character (\) or a character string enclosed in quotation marks. If such a case, you must use the shell variables themselves.
- #2
The HOME shell variable is not specified automatically. You must define it as an environment variable.