Bird
0
0

What will be the output of this script snippet?

medium📝 Command Output Q5 of 15
Bash Scripting - Conditionals
What will be the output of this script snippet?
file="/etc/passwd"
if [ -r "$file" ]; then
  echo "Readable"
else
  echo "Not readable"
fi
ANot readable
BNo output
CSyntax error
DReadable
Step-by-Step Solution
Solution:
  1. Step 1: Understand -r test

    -r tests if the file is readable by the user running the script.
  2. Step 2: Check /etc/passwd readability

    /etc/passwd is a standard readable file on most systems, so condition is true.
  3. Final Answer:

    Readable -> Option D
  4. Quick Check:

    File readable test -r = "Readable" output [OK]
Quick Trick: Use -r to check if file is readable [OK]
Common Mistakes:
MISTAKES
  • Not quoting file variable
  • Confusing -r with -w
  • Assuming file always unreadable

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes