Chapter 11 Flashcards

1
Q

A blank is a program written in an interpreted language, typically associated with a shell or other programs whose primary purpose is something other than as an interpreted language

A

script

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

In Linux, many scripts are blank, which are associated with Bash or another shell.

A

shell scripts

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

Shell scripts are blank, so you can create them in text editors, such as vi, nano, or pico

A

plain-text files

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

You shouldn’t use word processing programs to create shell scripts because they embed blank in the final document.

A

binary code

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

The first two characters of the command to a script are blank and is known as a blank

A

!

shebang

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

When you’re done writing the shell script, you should modify it so that it’s executable with the blank command.

A

chmod

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

One of the most basic features of shell scripts is the ability to blank

A

run commands

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

Aside from the shebang, the script looks like commands that you would normally type except for what?

A

scripts list complete paths

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

If your script produces a no such file or directory error, you can use the blank command where command is the offending file

A

which

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

Each command in a script ends in a blank symbol, which tells the script to go to the next line(command)

A

ampersand (&)

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

The blank commands, such as ls, mv, cp, and rm are often used in scripts.

A

file manipulation commands

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

The blank command locates files that contain the string you specify, or it displays the lines that contain those strings in a single file

A

grep

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

The blank command searches for a patterns based on filenames, ownership, and similar characteristics

A

find

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

The blank command extracts text from fields in a file

A

cut

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

The blank program provides many of the capabilities of a conventional text editor but via commands that can be typed at a command prompt or entered in a script

A

sed

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

The blank command is a tool to use when a script must provide a message to the user

A

echo

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

The blank command can be used to send email from within a script

A

mail

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

Blank can help you expand the utility of scripts

A

variables

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

Variable’s blank can be passed as parameters to a script, generated internally to a script, or extracted from a script’s environment

A

values

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

Another type of variable that can be set from the output of a command is also identified by blank, but typically is given a name that at least begins with a letter

A

leading dollar signs

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

In addition to assigning variables with the equal sign, you can read variables from a standard input using the blank command

A

read

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

One special type of variable is an blank variable, which is assigned and accessed just like a shell script variable

A

environment variable

23
Q

Can you set an environment variables in one script and use in another script?

A

Yes

24
Q

Environment variables are often used in blank scripts

A

shell startup scripts

25
Q

The blank variable holds the exit status of the most recently executed command, which is an integer (usually 0) when terminated normally

A

$?

26
Q

Scripting languages support several types of blank, which enable a script to perform one of several actions contingent on some condition

A

conditional expressions

27
Q

The conditional expression uses blank around the condition

A

square brackets

28
Q

One common command that uses conditional expressions is the blank command

A

if

29
Q

An alternative form for a conditional expression uses the blank keyword rather than square brackets around the conditional

A

test

30
Q

If more than two outcomes are possible, you can use blank

A

case

31
Q

Give the syntax for case

A

case word in
pattern1) command(s) ;;
pattern2) command(s) ;;

esac

32
Q

For a case statement, word is likely to be a blank, and each pattern is a possible blank of the word

A

variable
value

33
Q

Each set of commands of a case statement must end with blank, and the case statement as a whole ends in the string blank

A

;;
esac

34
Q

In a case statement, if you want to have a blank, use a * as the final pattern, which matches any word, so the command will execute if no other pattern matches

A

default condition

35
Q

Conditional expressions are sometimes used in blank, which are structures that tell the script to perform the same task repeatedly until some condition is met

A

loops

36
Q

What command used with the for loop can generate a specific number of lines

A

seq

37
Q

Another type of loop is the blank loop, which executes as long as its condition is true

A

while

38
Q

A blank is a part of a script that performs a specific subtask and that can be called by name from other parts of the script

A

function

39
Q

Functions are defined by placing blank after the function name and enclosing the lines that make up the function with blank

A

parentheses
curly brackets

myfn() {
commands
}

40
Q

Ordinarily, a script’s exit status is the same as the last command the script called – that is, the script returns blank

A

$?

41
Q

You can control the exit value, or exit at any point by using the blank command

A

exit

42
Q

Exiting a command with a certain numeric value helps you in blank research

A

error

43
Q

If you use a variable to store the exit number, what should the syntax be for exiting

A

exit $variable

44
Q

After using a text editor to create a shell script, what step should you take before trying to use the script by typing its name.

A) Set one or more executable bits using chmod
B) Copy the script to the /usr/bin directory
C) Compile the script by typing bash scriptname
D) Run a virus checker on the script
E) Run a spell checker on the script

A

A

45
Q

Describe the effect of the following short script, cp1, if it’s called as cp1 big.c big.cc:
#!/bin/bash
cp $2 $1

A) It has the same effect as the cp command - copying the contents of big.c to big.cc
B) It compiles the c program and calls the result big.cc
C) It copies the contents of big.cc to big.c and eliminates old big.c
D) It converts the C program big.c to C++ big.cc
E) The script’s final line is invalid, so it won’t work

A

C

46
Q

What is the purpose of conditional expressions in shell scripts?

A) They prevent scripts from executing if license conditions aren’t met
B) They display information about the script’s computer environment
C) They enable the script to take different actions in response to variable data
D) They enable scripts to learn in a Pavlovian manner
E) They cause scripts to run at only certain times of day

A

C

47
Q

True or False: a user types myscript laser.txt to run a script called myscript. Within myscript, the $0 variable holds the laser.txt

A

False

48
Q

True or False: Valid looping statements in Bash include for, while, and until

A

True

49
Q

True or False: The following script launches three simultaneous instances of the terminal program.
#!/bin/bash
terminal
terminal
terminal

A

False

50
Q

You’ve written a simple shell script to do nothing but launch programs. to ensure the script works with most user shells, the first line is blank

A

!/bin/bash

51
Q

The blank Bash scripting command is used to display prompts for the user in a shell script.

A

echo

52
Q

The blank bash scripting command is used to control the program flow based on a variable that can take many values

A

case

53
Q

The blank Bash scripting command controls the return value generated by a script, independent of the other commands used in the script

A

exit