20 mixed quiz questions on Quoting and Control Statements.

20 mixed quiz questions on Quoting and Control Statements.


Quiz: Quoting and Control Statements

True/False Questions

1. True/False

Double quotes prevent all shell interpretation, including variable substitution and command substitution.

Answer: False
Explanation: Double quotes prevent some special character interpretation, but they still allow variable substitution and command substitution.


2. True/False

Single quotes prevent the shell from interpreting variables, command substitution, globs, and other metacharacters.

Answer: True


3. True/False

The backslash character can be used to remove the special meaning of a metacharacter.

Answer: True


4. True/False

The semicolon ; runs the next command only if the previous command succeeds.

Answer: False
Explanation: The semicolon runs commands one after another, even if the previous command fails.


Multiple Choice Questions

5. Multiple Choice

Which command correctly assigns the value hello there to the variable var?

A.

var=hello there

B.

var = “hello there”

C.

var=”hello there”

D.

var=’hello’ there

Answer: C


6. Multiple Choice

What will the following command display?

var=hello

echo ‘$var’

A. hello
B. $var
C. var
D. Nothing

Answer: B
Explanation: Single quotes prevent variable substitution.


7. Multiple Choice

What does command substitution allow you to do?

A. Delete a command from history
B. Run a command and use its output inside another command
C. Convert a local variable into an environment variable
D. Stop all special characters from working

Answer: B


8. Multiple Choice

Which control statement runs the next command only if the previous command succeeds?

A. ;
B. &&
C. ||
D. \

Answer: B


Multi-Select Questions

9. Multi-Select

Which of the following are shell metacharacters or special characters mentioned or implied in this topic?

Select all that apply.

A. *
B. ?
C. Space
D. &&
E. cat

Answers: A, B, C, D


10. Multi-Select

Which commands correctly use command substitution?

Select all that apply.

A.

echo Today is `date`

B.

echo Today is $(date)

C.

echo Today is date

D.

today=$(date)

echo “$today”

Answers: A, B, D


11. Multi-Select

Which statements about double quotes are correct?

Select all that apply.

A. They can keep words with spaces together
B. They allow variable substitution
C. They allow command substitution
D. They prevent absolutely all shell interpretation
E. They can help assign a value with spaces to a variable

Answers: A, B, C, E


12. Multi-Select

Which statements about control statements are correct?

Select all that apply.

A. ; runs commands one after another
B. && runs the next command only if the previous command succeeds
C. || runs the next command only if the previous command fails
D. && always runs the second command
E. || means command substitution

Answers: A, B, C


Fill in the Blank with Choices

13. Fill in the Blank

The command below uses __________ quotes.

echo “$var”

Choices:
A. single
B. double
C. back
D. no

Answer: B. double


14. Fill in the Blank

The symbol __________ is used as an escape character in the shell.

Choices:
A. ;
B. \
C. ||
D. &&

Answer: B. \


15. Fill in the Blank

The control statement __________ means logical OR.

Choices:
A. ;
B. &&
C. ||
D. $()

Answer: C. ||


Matching Questions

16. Matching

Match each quoting method with its purpose.

Quoting MethodPurpose
1. Double quotes ” “A. Prevent almost all shell interpretation
2. Single quotes ‘ ‘B. Escape one special character
3. Backslash \C. Allow variables and command substitution while grouping text
4. Backquotes ` `D. Perform command substitution

Answer:

Quoting MethodCorrect Purpose
Double quotes ” “C
Single quotes ‘ ‘A
Backslash \B
Backquotes ` `D

17. Matching

Match each control statement with its meaning.

Control StatementMeaning
1. ;A. Run next command only if previous command fails
2. &&B. Run commands one after another
3. `

Answer:

Control StatementCorrect Meaning
;B
&&C
`

Ordering Questions

18. Ordering

Put the steps in the correct order to create a variable with spaces and display it.

A. Display the variable using echo “$var”
B. Use double quotes around the value
C. Assign the value using var=”hello there”

Correct Order:

  1. B
  2. C
  3. A

Final Commands:

var=”hello there”

echo “$var”


19. Ordering

Put the commands in the correct order to test whether /home exists and print success or failure.

A.

echo failure

B.

ls /home

C.

echo success

D.

&&

E.

||

Correct Order:

  1. B
  2. D
  3. C
  4. E
  5. A

Final Command:

ls /home && echo success || echo failure


Short Answer / Higher-Order Questions

20. Short Answer

A student writes the following command and gets an error:

var=hello there

Explain why this happens and write the corrected command.

Sample Answer:
The shell treats the space as a separator. It reads var=hello as one part and there as another command or statement. Since there is not a valid command, an error occurs.

Correct command:

var=”hello there”

The double quotes keep hello there together as one value.

Leave a Reply