The terms 'file descriptor' and 'file handle' are often used interchangeably.
>out.txt
section is actually a shorthand for 1>out.txt
. It instructs Bash to take anything that find
writes to FD =1 (stdout) and re-write it to the file called 'out.txt'.2> &1
section instructs Bash to take anything find
writes 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.
ls
writes 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.
ls
is still connected to the terminal (ls
is just ignoring it)grep
is 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.print
to write to stdout. Print is a common function for writing to stdout and print
or similar exists in most languages. Under the hood print
literally writes to stdout: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.
Bash
but it could be called Powershell
.