OPS435 Quiz #3 - Solution

Student Name: _____________________________________________

Multiple Choice / Multiple Answer / True or False

  1. Which of the following represent determinant loops (i.e. the number of repetitions are known in advance)? (Select all that apply)

    a) until b) while c) case d) for

  2. Which of the following control flow statements are more efficient to use with contant values (such as the value being either 1, 2, 3 or 4)?

    a) if b) case c) if-else d) if-elif-else

  3. Functions can only be used in shell scripts.

    a) true b) false (can be used in the shell as well)

  4. Which of the following complex regular expression symbols mean zero or more occurences of the preceeding character (i.e. character that comes “before”)

    a) . b) ? c) * d) {0,1}

Write a Function for a bash shell script

Write a portable Bash shell script to called validate.bash that prompts the user for an integer (i.e. a simple number, no signs or decimal places). If the user enters an invalid integer, indicate that what user entered is invalid and to re-try. Write the script below:


function check()


read -p "Please enter an integer: " integer

until echo $integer | grep -q "^[0-9][0-9]*$"


read -p "Invalid integer. Please re-enter: " integer