Deck 10: Shell Scripting
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/25
Play
Full screen (f)
Deck 10: Shell Scripting
1
A user needs the following permissions to be able to use a script as a command
A) Read and write
B) Write
C) Read
D) Execute
A) Read and write
B) Write
C) Read
D) Execute
Execute
2
The pipe operator, which directs the output from one command to another, is
A) /
B) #
C) |
D) >
A) /
B) #
C) |
D) >
C
3
Consider the following script. The output will be newlines replaced by spaces for brevity): #! /bin/bash
for number in
do
echo snumber
done
A) 5 .. 1
B) 5 4 3 2 1
C) 1 2 3 4 5
D) 5 3 1
for number in
do
echo snumber
done
A) 5 .. 1
B) 5 4 3 2 1
C) 1 2 3 4 5
D) 5 3 1
5 4 3 2 1
4
The command to view the contents of a variable at the shell prompt is
A) variablename
B) echo variablename
C) echo $variablename
D) $variablename
A) variablename
B) echo variablename
C) echo $variablename
D) $variablename
Unlock Deck
Unlock for access to all 25 flashcards in this deck.
Unlock Deck
k this deck
5
Consider the following script. The output will be newlines replaced by spaces):#! /bin/bash
for number in
do
echo snumber
done
A) 1 3 5 7
B) 1 4
C) 1 4 7
D) 7 4 1
for number in
do
echo snumber
done
A) 1 3 5 7
B) 1 4
C) 1 4 7
D) 7 4 1
Unlock Deck
Unlock for access to all 25 flashcards in this deck.
Unlock Deck
k this deck
6
The cat command in Linux is used to
A) Edit a shell script
B) Execute a shell script
C) Display the contents of a file
D) Find files
A) Edit a shell script
B) Execute a shell script
C) Display the contents of a file
D) Find files
Unlock Deck
Unlock for access to all 25 flashcards in this deck.
Unlock Deck
k this deck
7
Consider the following script. The output will be:
#! /bin/bash
guess = 2
start = 3
check = $ $start )
if [ $guess -eq $check]
then
echo "Correct Guess: The number is $start"
else
echo "Sorry, wrong guess"
A) Correct Guess: The number is 3
B) Correct Guess: The number is 2
C) Sorry, wrong guess
D) Indeterminate
#! /bin/bash
guess = 2
start = 3
check = $ $start )
if [ $guess -eq $check]
then
echo "Correct Guess: The number is $start"
else
echo "Sorry, wrong guess"
A) Correct Guess: The number is 3
B) Correct Guess: The number is 2
C) Sorry, wrong guess
D) Indeterminate
Unlock Deck
Unlock for access to all 25 flashcards in this deck.
Unlock Deck
k this deck
8
File users.csv contains lines as: Christine:Riggs:christine.riggs@sunshine.edu. The command to extract emails from the file is
A) cut -d: -f3 users.csv
B) cut -d, -f3 users.csv
C) cut -d: -f1,2,3 users.csv
D) cut -d, -f1,2,3 users.csv
A) cut -d: -f3 users.csv
B) cut -d, -f3 users.csv
C) cut -d: -f1,2,3 users.csv
D) cut -d, -f1,2,3 users.csv
Unlock Deck
Unlock for access to all 25 flashcards in this deck.
Unlock Deck
k this deck
9
Consider the following script. The output will be newlines replaced by spaces): #! / bin/bash
for number in
do
echo $number
done
A) 1 3 5 7
B) 1 4
C) 1 4 7
D) 7 4 1
for number in
do
echo $number
done
A) 1 3 5 7
B) 1 4
C) 1 4 7
D) 7 4 1
Unlock Deck
Unlock for access to all 25 flashcards in this deck.
Unlock Deck
k this deck
10
In programming languages, loops are used to
A) Loop through the execution logic and understand the program
B) Collect all comments
C) Mark the beginning and end of the program
D) Repeat a set of commands
A) Loop through the execution logic and understand the program
B) Collect all comments
C) Mark the beginning and end of the program
D) Repeat a set of commands
Unlock Deck
Unlock for access to all 25 flashcards in this deck.
Unlock Deck
k this deck
11
Comment lines in script begin with the character
A) /
B) #
C) |
D) >
A) /
B) #
C) |
D) >
Unlock Deck
Unlock for access to all 25 flashcards in this deck.
Unlock Deck
k this deck
12
Shell scripts are
A) A list of shell commands in a text file
B) Scripts used as a shell, with no content until used
C) A type of compiled programs
D) Lists of drugs prescribed by a physician
A) A list of shell commands in a text file
B) Scripts used as a shell, with no content until used
C) A type of compiled programs
D) Lists of drugs prescribed by a physician
Unlock Deck
Unlock for access to all 25 flashcards in this deck.
Unlock Deck
k this deck
13
The redirect operator used to send the output of a command to a file is written as
A) /
B) #
C) |
D) >
A) /
B) #
C) |
D) >
Unlock Deck
Unlock for access to all 25 flashcards in this deck.
Unlock Deck
k this deck
14
Consider the following script. The output will be: #! /bin/bash
guess=2
check=$ $RANDOM )
if [ $guess -eq $check]
then
echo "Correct Guess: The number is $check"
else echo "Sorry, wrong guess"
A) Correct Guess: The number is 3
B) Indeterminate
C) Correct Guess: The number is 2
D) Sorry, wrong guess
guess=2
check=$ $RANDOM )
if [ $guess -eq $check]
then
echo "Correct Guess: The number is $check"
else echo "Sorry, wrong guess"
A) Correct Guess: The number is 3
B) Indeterminate
C) Correct Guess: The number is 2
D) Sorry, wrong guess
Unlock Deck
Unlock for access to all 25 flashcards in this deck.
Unlock Deck
k this deck
15
A specific set of commands is to be executed 10 times. The most appropriate loop construct to accomplish this is
A) for
B) while
C) do
D) if
A) for
B) while
C) do
D) if
Unlock Deck
Unlock for access to all 25 flashcards in this deck.
Unlock Deck
k this deck
16
Shell scripts can obtain user input using the command
A) input
B) var
C) read
D) cat
A) input
B) var
C) read
D) cat
Unlock Deck
Unlock for access to all 25 flashcards in this deck.
Unlock Deck
k this deck
17
The command that will create a new variable in a bash script is
A) let firstname = "John"
B) firstname="John"
C) string firstname = "John"
D) str firstname = "John"
A) let firstname = "John"
B) firstname="John"
C) string firstname = "John"
D) str firstname = "John"
Unlock Deck
Unlock for access to all 25 flashcards in this deck.
Unlock Deck
k this deck
18
The first line of an executable script needs to be #!/bin/bash, in order to
A) Inform the shell which shell interpreter to use to execute the script
B) Remind the user of the shell interpreter to use when executing the script
C) Remind the user of the shell interpreter used to create the script
D) Serve as a comment for the shell interpreter when executing the script
A) Inform the shell which shell interpreter to use to execute the script
B) Remind the user of the shell interpreter to use when executing the script
C) Remind the user of the shell interpreter used to create the script
D) Serve as a comment for the shell interpreter when executing the script
Unlock Deck
Unlock for access to all 25 flashcards in this deck.
Unlock Deck
k this deck
19
Shell scripts are used for
A) Serving as firewalls
B) Automating processes in operating systems
C) End-point protection
D) Detecting intrusions
A) Serving as firewalls
B) Automating processes in operating systems
C) End-point protection
D) Detecting intrusions
Unlock Deck
Unlock for access to all 25 flashcards in this deck.
Unlock Deck
k this deck
20
Environment variables are
A) Variables describing the user's access to the computer environment
B) Variables describing the local climate
C) Variables describing the state of the host system
D) Variables created automatically when a user starts a new terminal window
A) Variables describing the user's access to the computer environment
B) Variables describing the local climate
C) Variables describing the state of the host system
D) Variables created automatically when a user starts a new terminal window
Unlock Deck
Unlock for access to all 25 flashcards in this deck.
Unlock Deck
k this deck
21
Consider the following script. The output will be newlines replaced by spaces for brevity): #! /bin/bash
counter=1
while [ \$counter -le 5]
do
echo $counter
counter=$counter )
done
A) 5 .. 1
B) 5 4 3 2 1
C) 1 2 3 4 5
D) 5 3 1
counter=1
while [ \$counter -le 5]
do
echo $counter
counter=$counter )
done
A) 5 .. 1
B) 5 4 3 2 1
C) 1 2 3 4 5
D) 5 3 1
Unlock Deck
Unlock for access to all 25 flashcards in this deck.
Unlock Deck
k this deck
22
The difference between break and continue while processing loop input is that
A) break exits the loop, but continue only exits the current iteration of the loop
B) break only exits the current iteration of the loop, but continue exits the loop
C) break and continue exit the loop
D) break and continue both exit only the current iteration of the loop
A) break exits the loop, but continue only exits the current iteration of the loop
B) break only exits the current iteration of the loop, but continue exits the loop
C) break and continue exit the loop
D) break and continue both exit only the current iteration of the loop
Unlock Deck
Unlock for access to all 25 flashcards in this deck.
Unlock Deck
k this deck
23
A specific set of commands is to be executed until a pre-specified condition is reached. The most appropriate loop construct to accomplish this is
A) for
B) while
C) do
D) if
A) for
B) while
C) do
D) if
Unlock Deck
Unlock for access to all 25 flashcards in this deck.
Unlock Deck
k this deck
24
An infinite loop a loop that runs forever can sometimes be useful
Unlock Deck
Unlock for access to all 25 flashcards in this deck.
Unlock Deck
k this deck
25
Consider the following script. The output will be newlines replaced by spaces for brevity): #! /bin/bash
counter=1
while [ $counter -le 2]
do
echo $counter
done
A) 5 .. 1
B) 5 4 3 2 1
C) 1 2 3 4 5
D) 1 1 1 1 1 1 ……. indefinitely)
counter=1
while [ $counter -le 2]
do
echo $counter
done
A) 5 .. 1
B) 5 4 3 2 1
C) 1 2 3 4 5
D) 1 1 1 1 1 1 ……. indefinitely)
Unlock Deck
Unlock for access to all 25 flashcards in this deck.
Unlock Deck
k this deck