How many ways are there in total to feed a command with input?

To begin with, sort << HERE and so on is not a here-string. That's a here-document. The here-string uses the <<< operator. That's in bash (and some other shells).

In general, there are two ways. One is through standard input (and redirections), and the other one is through parameters.

  1. Standard input and its redirections

    This is the stream that is by default connected to the terminal, in which a command executes and is associated with fd (file descriptor) 1. It's fed whatever is typed to the terminal. Though it (the input) can be redirected as in using the pipe | or using the here-documents or here-strings. Then the input doesn't come from the terminal, but is attached to the standard output of the command preceding the pipe. Different shells have different redirections, so for this category you should check the shell documentation. Look for input redirections.

  2. Parameters

    This is what in your example is sort foo. Calling a program or a function you pass it one or more parameters. A local file is just one possibility. The parameter might contain a URL or whatever. The options here are endless.

To sum up, there are two general ways:

  • the first one abstracts from the application's inner logic and manipulates the standard input on the OS/shell level,

  • while the second one involves the application's innards, and it's them that offer limitless possibilities, basing on the call parameters as an interface.

For both ways the answer is there are no limits. Though the actual limits come with the OS/shell and the application itself.


At least the following:

  1. Command options: foo --bar

  2. Standard input: foo | bar or bar < foo

  3. File(s): foo *.* (or by opening file(s) via code in foo) †

  4. Environment export: export foo=bar; baz

  5. Environment (without export): foo=bar baz or env foo=bar baz

  6. HERE doc: foo << EOF bar EOF

  7. HERE string: foo <<< bar

  8. Signals kill -SIGUSR1 $procid

  9. A whole variety of inter-process communications, such as sockets, TCP, memory-mapped files

† yes, I realize stdin is a file (or file-like). And that passing in files like this is really the same as passing in options