Deck 5: Creating Shell Scripts and Displaying File Contents

Full screen (f)
exit full mode
Question
The functions of the three permission types (read, write, and execute) are applied the same for files and directories.
Use Space or
up arrow
down arrow
to flip the card.
Question
By default, only root can execute a file automatically.
Question
Successful commands usually return the code 0 to the shell.
Question
You can use condition statements to create menu scripts that allow users to choose from a list of options.
Question
The if statement can only return a binary zero or one condition.
Question
Which symbol represents a permission that has not been granted?

A) Asterisk (*)
B) Carrot (^)
C) Hyphen (-)
D) Forward slash (/)
Question
Which command removes write and execute permissions for the other category on file4?

A) chmod o-wx file4
B) chmod file4 o-wx
C) rem file4 o-wx
D) del o-wx file4
Question
What is the corresponding numeric notation for a file with rw-rw-r-- permissions?

A) 221
B) 664
C) 110
D) 441
Question
____ consists of binary ones and zeros.

A) Script code
B) Variable code
C) Pseudocode
D) Machine code
Question
The BASH shell is an example of a(n)____.

A) interpreter
B) compiler
C) kernel file
D) machine code file
Question
With a compiled program, all the source code is converted to machine code and stored in a ____ before the user runs the script.

A) temporary file
B) buffer
C) binary file
D) variable
Question
Which command is used to display a list of all environment variables and their stored values?

A) dev
B) $echo
C) env
D) dvar
Question
Which variable assignment method would you use to specify a variable's value in a script command?

A) Conditional
B) Direct assignment
C) Prompt
D) Positional parameter
Question
Which variable assignment method is useful when you need information from the user to complete the script?

A) Conditional
B) Direct assignment
C) Prompt
D) Positional parameter
Question
When you run the scr1 script using the ./scr1 command, the filename is considered position zero in the command, and the text ./scr1 becomes the value of the ____ variable.

A) $0
B) $1
C) $run
D) $command
Question
Which command will display the exit status code on the screen?

A) env scode
B) echo $?
C) dis code
D) sh
Question
Which command ends a case statement?

A) ;;end
B) !!end
C) stop
D) esac
Question
The case statement syntax requires a(n) ____ to mark the end of each code portion matching a specific value.

A) period (.)
B) exclamation mark(!)
C) double semicolon (;;)
D) double exclamation mark(!!)
Question
The cat command is usually used to display the contents of a ____.

A) large text file
B) log file
C) small text file
D) memory dump
Question
The head command displays the first ____ lines of a text file.

A) two
B) five
C) ten
D) 100
Question
What is the result of running the head -15 scr8 command?

A) The command displays the last 15 lines of the scr8 file.
B) The command displays the first 15 lines of the scr8 file.
C) The command displays the contents of the scr8 file without the last 15 lines.
D) The command displays the contents of the scr8 file starting at line 15.
Question
What is the result of running the tail +5 scr8 command?

A) The command displays the last five lines of the scr8 file.
B) The command displays every fifth line of the scr8 file.
C) The command displays the contents of the scr8 file in reverse, five times.
D) The command displays the contents of the scr8 file starting at line five.
Question
Which command displays a file's contents one screen at a time?

A) head
B) show
C) echo
D) more
Question
Which command works the same as the more command but offers more flexibility in navigation?

A) less
B) dis
C) down
D) show
Question
A(n) ____________________ is a set of rules for instructing a computer how to perform specific tasks.
Question
With a(n) ____________________ program, the source code is converted to machine code, line by line, as the user runs the script.
Question
The purpose of a(n) ____________________ is to add documentation information for users and anyone else who might need to modify the script.
Question
When you quit a program or a command, a numeric code called a(n) ____________________ is sent to the shell.
Question
____________________ is used to perform a set of commands repeatedly.
Question
Match each statement with an item

-Indicates the end of the condition being tested.

A) if statement
B) then statement
C) else statement
D) fi statement
E) while statement
F) until statement
G) for statement
H) do statement
I) done statement
Question
Match each statement with an item

-Indicates the end of the code to be repeated.

A) if statement
B) then statement
C) else statement
D) fi statement
E) while statement
F) until statement
G) for statement
H) do statement
I) done statement
Question
Match each statement with an item

-A loop statement that specifies the number of times to execute the portion of code.

A) if statement
B) then statement
C) else statement
D) fi statement
E) while statement
F) until statement
G) for statement
H) do statement
I) done statement
Question
Match each statement with an item

-A loop statement that causes the interpreter to continue executing the code in the until loop portion of the script as long as the condition is false.

A) if statement
B) then statement
C) else statement
D) fi statement
E) while statement
F) until statement
G) for statement
H) do statement
I) done statement
Question
Match each statement with an item

-Starts the condition being tested.

A) if statement
B) then statement
C) else statement
D) fi statement
E) while statement
F) until statement
G) for statement
H) do statement
I) done statement
Question
Match each statement with an item

-A loop statement that tests a condition in much the same way as if-then statements.

A) if statement
B) then statement
C) else statement
D) fi statement
E) while statement
F) until statement
G) for statement
H) do statement
I) done statement
Question
Match each statement with an item

-Starts the portion of code specifying what to do if the condition evaluates to false.

A) if statement
B) then statement
C) else statement
D) fi statement
E) while statement
F) until statement
G) for statement
H) do statement
I) done statement
Question
Match each statement with an item

-Indicates the beginning of the code to be repeated.

A) if statement
B) then statement
C) else statement
D) fi statement
E) while statement
F) until statement
G) for statement
H) do statement
I) done statement
Question
Match each statement with an item

-Starts the portion of code specifying what to do if the condition evaluates to true.

A) if statement
B) then statement
C) else statement
D) fi statement
E) while statement
F) until statement
G) for statement
H) do statement
I) done statement
Question
Identify and define the three categories of file permissions.
Question
Why should you give only read and write permission to a file that is not a program?
Question
Why is it essential to understand the basics of shell scripting?
Question
After creating a shell script and assigning execute permissions, how do you define its stored location and why must you do this?
Question
Describe a shell variable.
Question
How do you combine the else and if statements? Why is this advantageous?
Question
Describe the case statement.
Question
Describe an until loop.
Question
Describe a for loop.
Question
Which command can be used to display a text file's contents in reverse order and why might a user want to do this?
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/48
auto play flashcards
Play
simple tutorial
Full screen (f)
exit full mode
Deck 5: Creating Shell Scripts and Displaying File Contents
1
The functions of the three permission types (read, write, and execute) are applied the same for files and directories.
False
2
By default, only root can execute a file automatically.
False
3
Successful commands usually return the code 0 to the shell.
True
4
You can use condition statements to create menu scripts that allow users to choose from a list of options.
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
5
The if statement can only return a binary zero or one condition.
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
6
Which symbol represents a permission that has not been granted?

A) Asterisk (*)
B) Carrot (^)
C) Hyphen (-)
D) Forward slash (/)
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
7
Which command removes write and execute permissions for the other category on file4?

A) chmod o-wx file4
B) chmod file4 o-wx
C) rem file4 o-wx
D) del o-wx file4
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
8
What is the corresponding numeric notation for a file with rw-rw-r-- permissions?

A) 221
B) 664
C) 110
D) 441
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
9
____ consists of binary ones and zeros.

A) Script code
B) Variable code
C) Pseudocode
D) Machine code
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
10
The BASH shell is an example of a(n)____.

A) interpreter
B) compiler
C) kernel file
D) machine code file
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
11
With a compiled program, all the source code is converted to machine code and stored in a ____ before the user runs the script.

A) temporary file
B) buffer
C) binary file
D) variable
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
12
Which command is used to display a list of all environment variables and their stored values?

A) dev
B) $echo
C) env
D) dvar
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
13
Which variable assignment method would you use to specify a variable's value in a script command?

A) Conditional
B) Direct assignment
C) Prompt
D) Positional parameter
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
14
Which variable assignment method is useful when you need information from the user to complete the script?

A) Conditional
B) Direct assignment
C) Prompt
D) Positional parameter
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
15
When you run the scr1 script using the ./scr1 command, the filename is considered position zero in the command, and the text ./scr1 becomes the value of the ____ variable.

A) $0
B) $1
C) $run
D) $command
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
16
Which command will display the exit status code on the screen?

A) env scode
B) echo $?
C) dis code
D) sh
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
17
Which command ends a case statement?

A) ;;end
B) !!end
C) stop
D) esac
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
18
The case statement syntax requires a(n) ____ to mark the end of each code portion matching a specific value.

A) period (.)
B) exclamation mark(!)
C) double semicolon (;;)
D) double exclamation mark(!!)
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
19
The cat command is usually used to display the contents of a ____.

A) large text file
B) log file
C) small text file
D) memory dump
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
20
The head command displays the first ____ lines of a text file.

A) two
B) five
C) ten
D) 100
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
21
What is the result of running the head -15 scr8 command?

A) The command displays the last 15 lines of the scr8 file.
B) The command displays the first 15 lines of the scr8 file.
C) The command displays the contents of the scr8 file without the last 15 lines.
D) The command displays the contents of the scr8 file starting at line 15.
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
22
What is the result of running the tail +5 scr8 command?

A) The command displays the last five lines of the scr8 file.
B) The command displays every fifth line of the scr8 file.
C) The command displays the contents of the scr8 file in reverse, five times.
D) The command displays the contents of the scr8 file starting at line five.
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
23
Which command displays a file's contents one screen at a time?

A) head
B) show
C) echo
D) more
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
24
Which command works the same as the more command but offers more flexibility in navigation?

A) less
B) dis
C) down
D) show
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
25
A(n) ____________________ is a set of rules for instructing a computer how to perform specific tasks.
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
26
With a(n) ____________________ program, the source code is converted to machine code, line by line, as the user runs the script.
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
27
The purpose of a(n) ____________________ is to add documentation information for users and anyone else who might need to modify the script.
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
28
When you quit a program or a command, a numeric code called a(n) ____________________ is sent to the shell.
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
29
____________________ is used to perform a set of commands repeatedly.
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
30
Match each statement with an item

-Indicates the end of the condition being tested.

A) if statement
B) then statement
C) else statement
D) fi statement
E) while statement
F) until statement
G) for statement
H) do statement
I) done statement
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
31
Match each statement with an item

-Indicates the end of the code to be repeated.

A) if statement
B) then statement
C) else statement
D) fi statement
E) while statement
F) until statement
G) for statement
H) do statement
I) done statement
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
32
Match each statement with an item

-A loop statement that specifies the number of times to execute the portion of code.

A) if statement
B) then statement
C) else statement
D) fi statement
E) while statement
F) until statement
G) for statement
H) do statement
I) done statement
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
33
Match each statement with an item

-A loop statement that causes the interpreter to continue executing the code in the until loop portion of the script as long as the condition is false.

A) if statement
B) then statement
C) else statement
D) fi statement
E) while statement
F) until statement
G) for statement
H) do statement
I) done statement
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
34
Match each statement with an item

-Starts the condition being tested.

A) if statement
B) then statement
C) else statement
D) fi statement
E) while statement
F) until statement
G) for statement
H) do statement
I) done statement
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
35
Match each statement with an item

-A loop statement that tests a condition in much the same way as if-then statements.

A) if statement
B) then statement
C) else statement
D) fi statement
E) while statement
F) until statement
G) for statement
H) do statement
I) done statement
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
36
Match each statement with an item

-Starts the portion of code specifying what to do if the condition evaluates to false.

A) if statement
B) then statement
C) else statement
D) fi statement
E) while statement
F) until statement
G) for statement
H) do statement
I) done statement
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
37
Match each statement with an item

-Indicates the beginning of the code to be repeated.

A) if statement
B) then statement
C) else statement
D) fi statement
E) while statement
F) until statement
G) for statement
H) do statement
I) done statement
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
38
Match each statement with an item

-Starts the portion of code specifying what to do if the condition evaluates to true.

A) if statement
B) then statement
C) else statement
D) fi statement
E) while statement
F) until statement
G) for statement
H) do statement
I) done statement
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
39
Identify and define the three categories of file permissions.
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
40
Why should you give only read and write permission to a file that is not a program?
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
41
Why is it essential to understand the basics of shell scripting?
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
42
After creating a shell script and assigning execute permissions, how do you define its stored location and why must you do this?
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
43
Describe a shell variable.
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
44
How do you combine the else and if statements? Why is this advantageous?
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
45
Describe the case statement.
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
46
Describe an until loop.
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
47
Describe a for loop.
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
48
Which command can be used to display a text file's contents in reverse order and why might a user want to do this?
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
locked card icon
Unlock Deck
Unlock for access to all 48 flashcards in this deck.