The terms 'file descriptor' and 'file handle' are often used interchangeably.
>out.txtsection is actually a shorthand for
1>out.txt. It instructs Bash to take anything that
findwrites to FD =1 (stdout) and re-write it to the file called 'out.txt'.
2> &1section instructs Bash to take anything
findwrites to FD=2 (stderr) and re-write it to FD=1. i.e. anything written to stderr (FD=2) should be re-written to stdout (FD=1).
The 'C' programming language has the same three properties and many other languages use the same names.
lswrites to it's stdout, is written to 'grep's stdin. The two apps are now connected via a 'pipe'.
A 'pipe' is just a program that reads from one FD and writes to another. When Bash sees the '|' character it takes it as an instruction to launch the two applications (ls and grep) read stdout from ls and write that data to stdin of grep.
lsis still connected to the terminal (
lsis just ignoring it)
grepis still connected to the terminal anything that grep writes to its stdout will appear on the terminal.
[print('hellow') -> stdout] -> [stdin -> terminal -> font -> graphics card -> eye -> brain]
print('hello')your app writes 'hello' to stdout, this arrives in the terminal app via its stdin.
In case you skipped the class, a command line interface (CLI) is a type of application referred to as a shell. A shell is designed to take keystrokes from a user, echo those keystrokes to the screen and when the user hits the enter key, try to interpret those keystrokes as a command. Often the command will be the name of an application, in which case the shell will start that application. Examples of shells are: Bash, Zsh, Powershell, cmd, Ash, Bourne, Korn, Hamilton............. and of course you could build your own.
Bashbut it could be called