IST 191 EXAM 1 QUESTIONS AND VERIFIED
ANSWERS
What is a bash shell script? - Answers - • A Bash shell script is an executable file that
contains a list of commands, with programming logic to control decision-making in the
overall task.
• When well-written, a shell script is a powerful command-line tool on its own.
What is a shebang? - Answers - • The first line of a script begins with the notation '#!',
commonly referred to as sh-bang or she-bang, from the names of those two characters,
sharp and bang.
• The syntax that follows the she-bang is the fully-qualified filename for the correct
command interpreter needed to process this script's lines.
Explain how to execute a bash shell script. - Answers - • Use the chmod command to
add execute permission, possibly in conjunction with the chown command to change
the file ownership of the script. Grant execute permission only for intended users of the
script.
• If you place the script in one of the directories listed in the shell's PATH environmental
variable, then you can invoke the shell script using the file name alone as with any other
command.
What are special characters in bash? - Answers - Special characters (as known as
metacharacters) are characters and words that have special meaning to the Bash shell
How do you change special characters to their literal value? - Answers - Use one of
three tools to remove or escape the special meaning: the backslash (\), single quotes ('
'), or double quotes (" ").
Explain the similarities and differences between single quotation marks and double
quotation marks when escaping special characters - Answers - • When you need to
escape more than one character in a text string, either use the escape character
multiple times or employ single quotes (''). Single quotes preserve the literal meaning of
all characters they enclose. Use single quotation marks to interpret all text literally.
• Use double quotation marks to suppress globbing and shell expansion, but still allow
command and variable substitution.
echo command - Answers - The echo command displays text by passing the text as an
argument to the command and the echo command can also be very helpful when trying
to debug a problematic shell script.
Explain what a loop is? - Answers - Repetitive tasks can take the form of executing an
action multiple times on a target, such as checking a process every minute for 10
, minutes to see if it has completed. Task repetition can also take the form of executing
an action once across multiple targets, such as backing up each database on a system
for loop - Answers -
Select Loop - Answers - The select loop provides an easy way to create a numbered
menu from which users can select options
while loop - Answers - The while loop enables you to execute a set of commands
repeatedly until some condition occur. The while loop is perfect for a situation where
you need to execute a set of commands while some condition is true
What is an exit code? - Answers - An exit code is a code that is returned after a process
has completed. An exit code value of 0 represents no error. All other nonzero values
indicate an error exit code
What does the test command do? - Answers - • The test command produces an exit
code upon completion, which is stored as the value $?.
• test 1 -gt 0 ; echo $? (example)
= - Answers - • = is the assignment operator, which assigns a value to a variable
[ Mark = Mark ] ; echo $? output 0 or has no error
== - Answers - • == is the equality operator, which compares two values or expressions
[ Mark == mark ] ; echo $? output 1 or has an error
!= - Answers - • != is the not equality operator, which compares two values or
expressions
[Mark != mark ] ; echo $? output 0 or has no error
What is a condition structure in bash shell scripting? - Answers - • Conditional structures
allow users to incorporate decision making into shell scripts, so that certain portions of
the script are executed only when certain conditions are met
Define regular expression - Answers - Regular expressions provide a pattern matching
mechanism that facilitates finding specific content. The vim , grep, and less commands
can all use regular expressions. Programming languages such as Perl, Python, and C
can all use regular expressions when using pattern matching criteria. Regular
expressions are a language of their own, which means they have their own syntax and
rules. The simplest regular expression is an exact match. An exact match is when the
characters in the regular expression match the type and order in the data that is being
searched.
Line Anchor - Answers - in regular expression, controls the location of where the regular
expression looks for a match
ANSWERS
What is a bash shell script? - Answers - • A Bash shell script is an executable file that
contains a list of commands, with programming logic to control decision-making in the
overall task.
• When well-written, a shell script is a powerful command-line tool on its own.
What is a shebang? - Answers - • The first line of a script begins with the notation '#!',
commonly referred to as sh-bang or she-bang, from the names of those two characters,
sharp and bang.
• The syntax that follows the she-bang is the fully-qualified filename for the correct
command interpreter needed to process this script's lines.
Explain how to execute a bash shell script. - Answers - • Use the chmod command to
add execute permission, possibly in conjunction with the chown command to change
the file ownership of the script. Grant execute permission only for intended users of the
script.
• If you place the script in one of the directories listed in the shell's PATH environmental
variable, then you can invoke the shell script using the file name alone as with any other
command.
What are special characters in bash? - Answers - Special characters (as known as
metacharacters) are characters and words that have special meaning to the Bash shell
How do you change special characters to their literal value? - Answers - Use one of
three tools to remove or escape the special meaning: the backslash (\), single quotes ('
'), or double quotes (" ").
Explain the similarities and differences between single quotation marks and double
quotation marks when escaping special characters - Answers - • When you need to
escape more than one character in a text string, either use the escape character
multiple times or employ single quotes (''). Single quotes preserve the literal meaning of
all characters they enclose. Use single quotation marks to interpret all text literally.
• Use double quotation marks to suppress globbing and shell expansion, but still allow
command and variable substitution.
echo command - Answers - The echo command displays text by passing the text as an
argument to the command and the echo command can also be very helpful when trying
to debug a problematic shell script.
Explain what a loop is? - Answers - Repetitive tasks can take the form of executing an
action multiple times on a target, such as checking a process every minute for 10
, minutes to see if it has completed. Task repetition can also take the form of executing
an action once across multiple targets, such as backing up each database on a system
for loop - Answers -
Select Loop - Answers - The select loop provides an easy way to create a numbered
menu from which users can select options
while loop - Answers - The while loop enables you to execute a set of commands
repeatedly until some condition occur. The while loop is perfect for a situation where
you need to execute a set of commands while some condition is true
What is an exit code? - Answers - An exit code is a code that is returned after a process
has completed. An exit code value of 0 represents no error. All other nonzero values
indicate an error exit code
What does the test command do? - Answers - • The test command produces an exit
code upon completion, which is stored as the value $?.
• test 1 -gt 0 ; echo $? (example)
= - Answers - • = is the assignment operator, which assigns a value to a variable
[ Mark = Mark ] ; echo $? output 0 or has no error
== - Answers - • == is the equality operator, which compares two values or expressions
[ Mark == mark ] ; echo $? output 1 or has an error
!= - Answers - • != is the not equality operator, which compares two values or
expressions
[Mark != mark ] ; echo $? output 0 or has no error
What is a condition structure in bash shell scripting? - Answers - • Conditional structures
allow users to incorporate decision making into shell scripts, so that certain portions of
the script are executed only when certain conditions are met
Define regular expression - Answers - Regular expressions provide a pattern matching
mechanism that facilitates finding specific content. The vim , grep, and less commands
can all use regular expressions. Programming languages such as Perl, Python, and C
can all use regular expressions when using pattern matching criteria. Regular
expressions are a language of their own, which means they have their own syntax and
rules. The simplest regular expression is an exact match. An exact match is when the
characters in the regular expression match the type and order in the data that is being
searched.
Line Anchor - Answers - in regular expression, controls the location of where the regular
expression looks for a match