Redirecting input

Many commands invoked from Bash read their input from one or more files provided on the command line, particularly the classic Unix text filtering tools, such as grep and sort. When these commands are passed one or more filenames as arguments, they switch to reading their input from those files in the order they were specified, instead of from their own standard input:

$ grep pattern myfile1 myfile2 myfile3
$ sort -k1,1 myfile1 myfile2 myfile3

This tends to mean that you do not need to use Bash to redirect input as often as you need to redirect output, because well-designed Unix programs can usually change their input behavior by specifying filenames, without any shell syntax involved.

However, not all programs behave this ...

Get Bash Quick Start Guide 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.