IFT Module 2
Which of the following will not result in an array called $MYVAR?
$MYARR[0]=Ness no dollar sign necessary for arrays in bash
Which of the following is not true regarding functions in BASH scripts: They can be used anywhere in the script following their declaration Their output can be captured and stored in a variable They return whatever is printed to stdout They can read and write to variables defined anywhere in the script.
They can read and write to variables anywhere in the script
Assume the following conditions are true: -the file "script.sh" exists -the current working directory is not in the path -script.sh has its execution bit enabled -script.sh contains a valied #! line with BASH as its interpreter Which of the following is not a valid command to invoke script.sh
script.sh
How many times will line 4 be evaluated? #!/bin/bash MYVAR=0 while (($MYVAR > 5)); do ((MYVAR++)) done
0
How many times will line 4 be evaluated #!/bin/bash MYVAR=0 until (($MYVAR > 5)); do ((MYVAR++)) done
6
A case statement matches a variable against a defined set of literal strings?
False
A case statement must contain a 'default case' in order to be valid
False
The first line of this script is a convention unique to BASH scripts. It tells BASH that the file is a script: @!/bin/bash echo -e "Hello, World"
False
How many times will line 3 be evaluated? #!/bin/bash MYVAR=0 until (($MYVAR >5)); do ((MYVAR++)) done
7
Briefly describe the difference between while loop and until loop in how it responds to the output of a condition
A while loop the loop commands will continue while the condition specified is true. Once the condition of the while loop is no longer true the loop will end execution. The until loop will run the loop of commands until the condition is true. The until loop will execute while the condition specified is false and once it is true the until loop will no longer execute.
You can reorder positional parameters using the command; -order -shift -change -set
shift
Which of the following is not true about this invocation of echo and its output echo -e "I'd buy that for $1!" I'd buy that for !
The -e option tells echo to expand the $1 variable name
The script provided will have no output. why? #!/bin/bash delcare -l MYVAR MYVAR='ORB' if [ $MYVAR - eq "ORB" ]; then VAR1=3 echo $MYVAR fi
The MYVAR variable does not contain 'ORB' On line 4 the =(equals) operator must be used
Give one advantage of using a case statment over an if statement, and one advantage of using an if statement over a case statment.
The case statement can compare a variable to multiple different conditions and depending on which condition is matched, it will execute the following commands under that condition which is helpful if you have several options and for each option you need to execute a different set of commands. The if statement is better than the case statement when you have a quick decision to make to determine the flow of the script. If statements are good for true and false decision making if true do this if false do this.
Which of the follwoing is NOT true regarding if statements in BASH scripts -They must contain the else keyword -They can optionally contain as many elif statements as needed -They begin with an if keyword and end with the fi keyword -They must contain the then keyword
They must contain the 'else' key word
Line 5 of this script is a 'comment' and will not be executed: line 5: #echo $MYVAR
True
The default behavior of the set command is to assign the value of the first positional parameter
True
Without the aid of additional tools, BASH can only perform arithmetic on integers
True
Select the expression that will complete the if statement and allow line 4 to execute: 1 #!/bin/bash 2 declare -l MYVAR='ORB' 3 if ????????; then 4 echo $MYVAR 5 fi
[$MYVAR -eq "orb"]
Which command would you use to delete an array within a shell script? -unset arrayName -remove arrayName -del arrayName -clear arrayName
unset arrayName