Flowcontrol and Redirects Flashcards
What are environmental
variables?
Each process has a defined environment in which it is executed. This environment contains certain variables that affect a process’ behaviour. Every variable contains certain values, which can be modified before calling an application.
What does the PATH environmental variable contain?
Contains a list of search paths for programs
What does the HOME environmental variable contain?
Contains the path to the user’s home directory
What does the USER environmental variable contain?
Contains the current user name
How can the content of a variable be listed?
Using a single command, the content of a variable can be listed if its name is known. If the name is unknown, all defined variables can be listed. For printing the variable’s content, the name must be prefixed with a $ sign.
What is a File Descriptor?
A File Descriptor is a low-level reference to a file, used by the kernel to access the file. Usually, it is a simple integer.
Why can you refer to the three standard streams with a file descriptor?
On Unix (and Linux), everything is a file or represented as a file. The same is true for the three standard streams.
What are the three standard streams?
Standard Input (stdin) = 0, Standard Output (stdout) = 1 as well as Standard Error (stderr) =2. Each program has at least those three file descriptors, represented by the numbers
These three standard streams allow for basic input/output operations of a program. In Java, you can access these streams as System.in, System.out and System.err.
What is Standard Input?
Standard Input is where the program receives its inputs from. In the case of a command line application, this can be the keyboard.
What is Standard Output?
Standard Output, on the other hand, is where the program prints its output to. Usually, this is the display in the case of a command line application.
What is Standard Error?
Standard Error is where all error messages of a program go to. This can be either configured as a log file or the screen, or both.
What for do you need Redirectors?
As it is not always desirable or practical to read from the keyboard when you want your inputs defined in a file, these standard streams can be redirected to other sources/destinations. For instance a log file, the printer, another program or the nirvana (/dev/null) if no output is desired.
How can you redirect a file?
< file Redirect STDIN to read from file
> file Redirect STDOUT to write to file
» file Redirect STOUT to append to file
What does the command “2> file” do?
Redirect STDERR to write to file
What does the command “2» file” do?
Redirect STDERR to append to file