Bird
0
0

You wrote a script myscript.sh but when you run ./myscript.sh, it says Permission denied. What is the likely fix?

medium📝 Debug Q14 of 15
Bash Scripting - Basics
You wrote a script myscript.sh but when you run ./myscript.sh, it says Permission denied. What is the likely fix?
ARun <code>chmod +x myscript.sh</code> to make it executable
BAdd <code>#!/bin/bash</code> at the top
CRename the file to <code>myscript.txt</code>
DRun the script with <code>bash myscript.sh</code> only
Step-by-Step Solution
Solution:
  1. Step 1: Understand the cause of 'Permission denied'

    This error usually means the file is not executable by the user.
  2. Step 2: Make the script executable

    Using chmod +x myscript.sh adds execute permission, allowing ./myscript.sh to run.
  3. Final Answer:

    Run chmod +x myscript.sh to make it executable -> Option A
  4. Quick Check:

    Permission denied fix = chmod +x [OK]
Quick Trick: Use chmod +x to allow script execution [OK]
Common Mistakes:
MISTAKES
  • Forgetting to make script executable
  • Only adding shebang without permissions
  • Renaming file instead of fixing permissions

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes