Class Test Script

Please go through the following script and identify the defects

UPDATE:

There was an issue with the way the MS Forms was created. So we have updated the Key below.

Question

!#/bash/bin
echo Please talk to me ...
while 
do
  read INPUT_STRING
  case INPUT_STRING 
        hello) echo "Hello yourself!" ;;
        bye)   echo "See you again!" break ;;
        #)     echo "Sorry, I don't understand" ;
  esac
echo
echo "That's all folks!"

Corrected Script

#!/bin/bash
echo "Please talk to me ..."
while true
do
  read INPUT_STRING
  case $INPUT_STRING 
        hello) echo "Hello yourself!" ;;
        bye)   echo "See you again!" break ;;
        *)     echo "Sorry, I don't understand" ;;
  esac
echo
echo "That's all folks!"

Key

Highlighted responses are correct

Q1: Which of the following are correct for the provided Bash Script?

  • Line 1: !#/bash/bin - This is incorrect - It should be #!/bin/bash

  • Line 2: echo Please talk to me ... - This is correct

  • Line 3: while - This is incorrect - it should as per the above solution to let the WHILE loop run

  • Line 5: read INPUT_STRING - This is correct

Q2: Which of the following are incorrect in provided Bash Script?

  • Line 1: !#/bash/bin - This is incorrect - It should be #!/bin/bash

  • Line 2: echo Please talk to me ... - This is correct

  • Line 3: while - This is incorrect - it should as per the above solution to let the WHILE loop run

  • Line 5: read INPUT_STRING - This is correct

Q3: Which of the following are missing in the provided Bash Script?

  • Line 11: done - As it is required to end the WHILE loop

  • Line 6: case $INPUTSTRING in - As we need to read the value of INPUT_STRING in case

  • Line 5: echo - It is not required as it doesn't matter if echo existed or not. So it is not considered missing.

  • None of the Above - Obviously not an answer here.

Q4: Which of the following is true for Line 9?

  • should be replaced by *

  • The line should end with ;;

  • *) echo "Sorry, I don't understand" ;; - is the correct final replacement

  • None of the above - Obviously not an answer here.

Q5: Which of the following correct in regards to the provided Bash Script?

  • The script takes in an input from console and responds based on CASE statements and repeated in WHILE loop

  • The scripts takes in an input from console and responds only based on WHILE loop

  • The script is completely incorrect and does nothing

  • None of the options are correct

Last updated

Was this helpful?