Skip to content

Files

Latest commit

 

History

History
31 lines (19 loc) · 992 Bytes

SC2261.md

File metadata and controls

31 lines (19 loc) · 992 Bytes

Pattern: Multiple redirections compete for stdout

Issue: -

Description

A file descriptor, whether stdin, stdout, stderr, or non-standard ones, can only point to a single file/pipe.

For input, many commands support processing multiple filenames. In these cases you can just specify the filenames instead of redirecting. Alternatively, you can use cat to merge multiple filenames into a single stream.

For output, you can use tee to write to multiple output sinks in parallel.

Example of incorrect code:

grep foo < input1 < input2 > output1 > output2 > output3

Example of correct code:

# Merge inputs into a single stream, write outputs individually
cat input1 input2 | grep foo | tee output1 output2 > output3

# Pass inputs as filenames, write outputs individually
grep foo input1 input2 | tee output1 output2 > output3

Further Reading