18. Shell I/O Redirection Flashcards

1
Q

Standard input: stdin

A

default data source for stdin
is the terminal (text entered at the keyboard)

it is possible to use special BASH shell syntax to change the data source of stdin to come from
somewhere else, such as a file.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Standard output: stdout

A

default data destination for
stdout is the terminal.

Data written to stdout by a LINUX command executed from a terminal
appears as text in output in the terminal window by default

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Standard error: stderr

A

stderr is an output data stream that programs can write data to.

The default destination for stderr
is the terminal.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Why have standard I/O streams

A

in LINUX the operating system provides
every program with these streams.

they become much more versatile,When commands use these streams for input and output,

because we can change where that input comes from and where that output goes at the level of the shell without having to modify the source code for the command and recompile it!

standard I/Ostreams are an abstraction of input and output that can be utilized by commands and manipulated
by the shell to achieve more versatile and customizable behavior from commands.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Why have two output streams?

A

separate actual program output
from diagnostic messages such as errors or warnings.

we can redirect stdout,
and still see the the diagnostic messages from stderr in the terminal.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Redirecting stdin

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Redirecting stdout

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

file descriptor

A

A file descriptor in the shell is just a number that the operating system assigns to an open I/O stream to or from a file in the filesystem

The file descriptor
of stdin is always 0.
file descriptor for stdout is always 1,
file descriptor for stderr is
always 2.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Redirection of stderr

A

need to specify the file descriptor 2 with the output redirect
operator,

wc -l < file_list .txt 2> error_log .txt

This would redirect stdin to come from the file file_list.txt, and redirect stderr to the file error_log.txt. In this example, stdout is not redirected and still goes to the terminal

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Simultaneously redirecting both stdout and stderr

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly