Redirection
Redirections are used to change where a command reads its input or sends its output. In general, redirections open, close, or duplicate an existing reference to a file.
The overall format used for redirection is as follows:
[ n ] redir-op file
where redir-op is one of the redirection operators listed below and n is an optional number that refers to a file descriptor. Following is a list of the possible redirections.
- [ n ]< file
- Redirect standard input (or n) from file.
- [ n1 ]<&n2
- Duplicate standard input (or n1) from file descriptor n2.
- [ n ]<&-
- Close standard input (or n).
- [ n ]> file
- Redirect standard output (or n) to file.
- [ n ]>| file
- Redirect standard output (or n) to file, but override the noclobber option.
- [ n ]>> file
- Append standard output (or n) to file.
- [ n1 ]>&n2
- Duplicate standard output (or n1) from n2.
- [ n ]>&-
- Close standard output (or n).
It is best not to use the /QSYS.LIB/QTEMP.LIB directory for redirections since it is deleted when a job ends and a new job is started and ended for each command.
Here-documents
The format of a here-document is as follows:
- [ n ]<<[-] delimiter
- here-doc-text ...
delimiter
All the text on successive lines up to delimiter is saved and made available to the command on standard input, or file descriptor n if it is specified. If delimiter as specified on the initial line is quoted, then here-doc-text is treated literally, otherwise the text is subjected to parameter expansion, command substitution, and arithmetic expansion. If the operator is <<- instead of <<, then leading tabs in here-doc-text are stripped.