Previous | Table of Contents | Next |
DESCRIPTION
The internal print command is a sophisticated echo command. It is the ksh s output command. The print command performs like echo unless options are used to change how it functions. Refer to the echo command described in Module 38.
COMMAND FORMAT
Following is the general format of the print command.
print [ - ] [ -nprRsu[n] ] [ args Options The following list describes the options and their arguments that may be used to control how print functions.
- | Ignore all following options. Causes print to perform exactly like the echo (SV) command. Same as no options. |
-n | Do not write a new-line at the end of the output. Performs the same function as the \c escape sequence. Conforms to BSD echo -n option. |
-r | Ignore the escape sequences used in the echo command. |
-R | Same as -r. Also ignores all options except for -n. |
-s | Write all arguments (the output) to the history file. |
-u n | Write all arguments (the output) to the file with file descriptor n . No new-line is written on the output. |
-p | Write all arguments (the output) to the pipe process spawned with the & command. |
The following examples will help clarify the use of these options.
cj> print -R -n "This \n is a prompt:" # ignores the \n and no new-line This is a prompt:cj> cj> print -s "vi mmrg" # enter the "vi mmrg" command # into the history file cj> print -p "Some info on the pipe" # write to the hidden shell pipe.
Arguments
The arguments to echo are whatever text you wish to write to the standard output. If no arguments are specified, then echo displays a blank line by writing a single new-line. You can use the following list of escape sequence characters to produce special output from echo :
CAUTION:
You must remember that the shell interprets the \ (backslash) as a special character. Therefore, it is recommended that you place your echo arguments inside double quotes.
\b | produces a backspace on the output |
\c | write the output, but do NOT terminate it with a new-line |
\f | produces a form feed |
\n | produces a new-line |
\r | produces a carriage return |
\t | produces a tab |
\v | produces a vertical tab |
\\ | produces a backslash |
\0 n | produces the ASCII character with the octal code of n . Where n is a 1-, 2-, or 3-digit octal number representing the desired character. |
DIAGNOSTICS AND BUGS
When you use the \0 n escape sequence you must always precede the n with a 0 (zero). This informs echo that the number is octal.
To use escape sequences you must either enclose them in double quotes, single quotes, or use two \ (backslashes).
If you need to use these escape characters, the octal equivalents can be found in Appendix G.
RELATED COMMANDS
Refer to the echo command described in Module 38 and the ksh command described in Module 71.
RELATED FILES
The output of print is sent to the standard output. Therefore, you may redirect it to a file or a pipe. It is also possible to send the output to the shell s background pipe, using the -p option. Refer to the & (vertical bar, ampersand) definition in the SPECIAL (META) CHARACTERS section of Module 71 on the ksh .
APPLICATIONS
The print command is used to display text and variables to the user s terminal. Since the standard output is the default, output may be redirected as desired. It is often used to direct known output into a pipe. The pipe may be the shell s own background pipe or a normal pipe. It is used in shell scripts to display return codes and debugging output. You use print to build menus and data entry screens. The select command should also be studied for menu building.
TYPICAL OPERATION
In this activity you use the echo command to display text and variables. You also use it to output new-lines, tabs, and no new-line via escape sequences. If you don t have the ksh, skip to the next module. Begin at the shell prompt.
cj> Escapek ... cj> print this # appeared after you pressed Escapek this # appeared after you pressed Return
Previous | Table of Contents | Next |