Bird
0
0

Consider this script snippet:

medium📝 Command Output Q5 of 15
Bash Scripting - Conditionals
Consider this script snippet:
if [ -x ./script.sh ]; then echo "Executable"; else echo "Not executable"; fi

What will it print if script.sh exists but is not executable?
AExecutable
BError message
CNot executable
DNo output
Step-by-Step Solution
Solution:
  1. Step 1: Understand the -x operator

    -x checks if the file has execute permission.
  2. Step 2: Evaluate the condition when file exists but is not executable

    The condition fails, so the else branch runs, printing "Not executable".
  3. Final Answer:

    Not executable -> Option C
  4. Quick Check:

    Execute permission missing = "Not executable" [OK]
Quick Trick: Check execute permission with -x before running scripts [OK]
Common Mistakes:
MISTAKES
  • Assuming existence means executable
  • Ignoring else branch
  • Confusing -r with -x

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes