Input-Output Redirection Flashcards

1
Q

Redirect standard output to a file

A

echo “test” > file.txt

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

Redirect and append standard output to a file

A

echo “test”&raquo_space; file.txt

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

Chain scripts, files, and commands together by STDOUT as STDIN for the next command

A

|

cat /etc/passwd | grep root

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

Redirect standard error

A

2>

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

Redirect STDERR to STDOUT

A

2>&1

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

Accept input from file

A

<

grep -i “ERROR” < /var/log/messages

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

What is a “here document”

A

A way to run an interactive program within a shell script without user action by supplying the required input for the interactive program, or interactive shell script

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

How do you use a here document

A
The general form for a here document is − 
command << delimiter
document
delimiter
The following script runs a session with the vi text editor and saves the input in the file test.txt.
#!/bin/sh

filename=test.txt
vi $filename <

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

Describe each file descriptor

A

&0 is STDIN
&1 is STDOUT
&2 is STDERR

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

Redirect STDOUT to STDERR

A

echo “test” >&2

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