What Is stdin Redirection? Feeding Input from a File
stdin redirection uses the < operator to feed the contents of a file (or another source) into a command as its standard input.
Most commands can read from stdin, and redirection lets you choose where that input comes from. The < operator points a command's stdin at a file instead of the keyboard. CI scripts use input redirection to feed SQL, config, or data files into tools without interactive typing, which matters because CI has no keyboard.
What stdin redirection is
The < operator connects a command's standard input to a file. sort < data.txt runs sort with the file's contents as its input, just as if you had typed them.
Redirection versus piping
A pipe sends one command's output into another's input; redirection sends a file's contents into a command's input. cat data.txt | sort and sort < data.txt achieve similar results, though redirection avoids an extra process.
Forms of input redirection
cmd < filefeeds a file as stdin.cmd <<EOF ... EOFfeeds an inline here-document.cmd <<< "text"feeds a single here-string.
Why use redirection
Input redirection lets a tool consume data without a user typing it, which is essential for automation. It also keeps scripts clean by avoiding unnecessary cat | command chains.
stdin redirection in CI
CI uses input redirection to feed prepared files into tools: a SQL script into a database client, a config into a generator. Because CI is non-interactive, redirecting a file into stdin is how you supply the input a tool would otherwise prompt for.
Feeding tools on managed runners
On Latchkey runners, redirecting a file into a command's stdin lets a step drive interactive-style tools without a human. Prepare the input file in an earlier command, then redirect it in, keeping the step fully automated.
Key takeaways
- stdin redirection uses
<to feed a file into a command as input. - It differs from a pipe, which connects one command's output to another.
- CI uses it to supply input non-interactively, since there is no keyboard.