Which of the following will output “cat”?

  1. a. case “dog” in *) echo cat;; esac

  2. b. case “cat” in cat) echo$1 exit

  3. c. case cat dog rabbit; echo $1

  4. d. echo cat | case $1 in cat) echo $1 ;; esac

  5. e. case (cat dog rabbit) {echo $2}


Correct Option: A

AI Explanation

To answer this question, let's go through each option to understand why it is correct or incorrect:

Option A) a. case "dog" in *) echo cat;; esac - This option is incorrect because the case statement is matching "dog" instead of "cat", so it will not output "cat".

Option B) b. case "cat" in cat) echo $1 exit - This option is incorrect because there is no closing parenthesis after the echo statement. Additionally, the exit command is missing a semicolon before it.

Option C) c. case cat dog rabbit; echo $1 - This option is incorrect because the case statement is missing the "in" keyword. Additionally, the echo statement is outside of the case statement.

Option D) d. echo cat | case $1 in cat) echo $1 ;; esac - This option is incorrect because the variable $1 is not defined before the case statement. Also, the pipe "|" operator is not being used correctly in this context.

Option E) e. case (cat dog rabbit) {echo $2} - This option is incorrect because the case statement is missing the "in" keyword. Additionally, the curly braces "{" and "}" are not used correctly in this context.

The correct answer is A) a. case "dog" in *) echo cat;; esac. This option is correct because the case statement matches "dog" and outputs "cat".

Therefore, the correct answer is A) a. case "dog" in *) echo cat;; esac.

Find more quizzes: