Output Redirections
For print
and printf
, dest-expr is an
optional expression that directs the output to a file or pipe.
-
>
file
Directs the output to a file, overwriting its previous contents.
-
>>
file
Appends the output to a file, preserving its previous contents. In both of these cases, the file will be created if it does not already exist.
-
|
command
Directs the output as the input to a system command.
-
|&
command
Directs the output as the input to a coprocess. gawk only.
Be careful not to mix >
and >>
for the same file.
Once a file has been opened with >
, subsequent output statements continue
to append to the file until it is closed.
Remember to call close()
when
you have finished with a file, pipe, or coprocess. If you don’t,
eventually you will hit the system limit on the number of
simultaneously open files.
Get Unix in a Nutshell, 4th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.