Bird
0
0

You want to check if a variable input is either "yes" or "y" (case insensitive) using [[ ]]. Which snippet correctly does this?

hard🚀 Application Q15 of 15
Bash Scripting - Conditionals
You want to check if a variable input is either "yes" or "y" (case insensitive) using [[ ]]. Which snippet correctly does this?
A[[ $input =~ ^(yes|y)$ ]]
B[[ $input == "yes" || $input == "y" ]]
C[[ ${input,,} == "yes" || ${input,,} == "y" ]]
D[[ $input == "yes" && $input == "y" ]]
Step-by-Step Solution
Solution:
  1. Step 1: Understand case-insensitive check

    To ignore case, convert input to lowercase using ${input,,} before comparison.
  2. Step 2: Check logical OR condition

    We want to accept either "yes" or "y", so use || between comparisons.
  3. Step 3: Evaluate options

    [[ ${input,,} == "yes" || ${input,,} == "y" ]] correctly converts to lowercase and uses OR. [[ $input == "yes" || $input == "y" ]] lacks case conversion. [[ $input =~ ^(yes|y)$ ]] uses regex but is case-sensitive. [[ $input == "yes" && $input == "y" ]] uses AND which requires both to be true, impossible here.
  4. Final Answer:

    [[ ${input,,} == "yes" || ${input,,} == "y" ]] -> Option C
  5. Quick Check:

    Use ${var,,} for lowercase and || for OR [OK]
Quick Trick: Use ${var,,} to lowercase and || for OR in [[ ]] [OK]
Common Mistakes:
MISTAKES
  • Not converting input to lowercase
  • Using && instead of || for alternatives
  • Incorrect regex syntax inside [[ ]]

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes