Bird
0
0

Identify the error in this bash snippet that checks if a file exists and is executable:

medium📝 Debug Q14 of 15
Bash Scripting - Conditionals
Identify the error in this bash snippet that checks if a file exists and is executable:
if [ -e myscript.sh -a -x ]; then echo "Executable file"; fi
AMissing filename after -x operator
BWrong operator -e should be -f
CMissing spaces around -a operator
DShould use double brackets [[ ]] instead of single [ ]
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the -x operator usage

    The -x operator requires a filename argument, but none is provided after it.
  2. Step 2: Check other parts of the condition

    -e myscript.sh is valid to check existence; spaces around -a are correct; using single brackets is valid.
  3. Final Answer:

    Missing filename after -x operator -> Option A
  4. Quick Check:

    -x needs a file name [OK]
Quick Trick: Always provide filename after each test operator [OK]
Common Mistakes:
MISTAKES
  • Forgetting filename after -x
  • Confusing -e and -f operators
  • Missing spaces around operators causing syntax errors

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes