It adds execute permission to the file script.sh, allowing it to be run as a program.
Click to reveal answer
beginner
Why do you need to make a script executable before running it?
Because the operating system requires execute permission to run a file as a program. Without it, you can only read or edit the script, not run it directly.
Click to reveal answer
intermediate
What is the difference between chmod +x script.sh and chmod 755 script.sh?
chmod +x adds execute permission to the existing permissions. chmod 755 sets read, write, and execute for owner and read and execute for group and others explicitly.
Click to reveal answer
beginner
How can you check if a script is executable?
Use ls -l script.sh. If you see an x in the permission string (e.g., -rwxr-xr-x), it means the script is executable.
Click to reveal answer
beginner
What happens if you try to run a script without execute permission?
You will get a 'Permission denied' error if you try to run it directly. However, you can still run it by calling the interpreter explicitly, like bash script.sh.
Click to reveal answer
What does chmod +x myscript.sh do?
ACopies the script
BMakes the script executable
CChanges the script owner
DDeletes the script
✗ Incorrect
The command adds execute permission to the script, allowing it to be run.
Which command shows if a file is executable?
Als -l filename
Bcat filename
Crm filename
Dtouch filename
✗ Incorrect
The ls -l command lists file permissions, showing if execute permission is set.
If a script is not executable, how can you still run it?
ABy running <code>bash script.sh</code>
BBy double-clicking it
CBy renaming it
DBy deleting it
✗ Incorrect
Calling the interpreter explicitly runs the script without needing execute permission.
What permission does chmod +x add?
ARead permission
BWrite permission
CDelete permission
DExecute permission
✗ Incorrect
The +x flag adds execute permission to the file.
What error appears if you run a script without execute permission?
ASyntax error
BFile not found
CPermission denied
DCommand not found
✗ Incorrect
Trying to run a non-executable script directly results in a 'Permission denied' error.
Explain why and how you make a script executable in bash.
Think about what the system needs to allow running a file as a program.
You got /3 concepts.
Describe how to check if a script is executable and what the permission string looks like.
Look at the file permissions shown by ls.
You got /3 concepts.
Practice
(1/5)
1. What does the command chmod +x script.sh do in bash scripting?
easy
A. Makes the script script.sh executable so it can be run directly.
B. Deletes the script script.sh from the system.
C. Copies the script script.sh to another location.
D. Changes the owner of the script script.sh.
Solution
Step 1: Understand the chmod command
The chmod command changes file permissions in Linux and Unix systems.
Step 2: Interpret the +x option
The +x option adds execute permission, allowing the file to be run as a program.
Final Answer:
Makes the script script.sh executable so it can be run directly. -> Option A
Quick Check:
chmod +x means add execute permission [OK]
Hint: Remember +x means add execute permission [OK]
Common Mistakes:
Confusing execute permission with deleting files
Thinking chmod copies files
Mixing up ownership change with permission change
2. Which of the following is the correct syntax to make a script named run.sh executable?
easy
A. chmod x run.sh
B. chmod x+ run.sh
C. chmod -x run.sh
D. chmod +x run.sh
Solution
Step 1: Recall the correct order of options in chmod
The correct syntax to add execute permission is chmod +x filename.
Step 2: Check each option
chmod +x run.sh matches the correct syntax exactly; others have incorrect order or missing symbols.
Final Answer:
chmod +x run.sh -> Option D
Quick Check:
Correct syntax is chmod +x filename [OK]
Hint: Use chmod +x filename to add execute permission [OK]
Common Mistakes:
Placing + and x in wrong order
Using -x which removes execute permission
Omitting the + sign
3. Given a script hello.sh without execute permission, what will be the output of the command sequence below?
ls -l hello.sh
chmod +x hello.sh
ls -l hello.sh
medium
A. Both ls -l commands show execute permission.
B. The first ls -l shows no execute permission; the second shows execute permission added.
C. The first ls -l shows execute permission; the second removes it.
D. Both ls -l commands show no execute permission.
Solution
Step 1: Understand initial permissions
Initially, hello.sh has no execute permission, so ls -l shows no 'x' in permissions.
Step 2: Apply chmod +x and check again
After running chmod +x hello.sh, execute permission is added, so the second ls -l shows 'x' in permissions.
Final Answer:
The first ls -l shows no execute permission; the second shows execute permission added. -> Option B
Quick Check:
Adding +x updates permissions visible in ls -l [OK]
Hint: Check permissions before and after with ls -l [OK]
Common Mistakes:
Assuming execute permission is present initially
Thinking chmod +x removes execute permission
Not noticing permission changes in ls -l
4. You try to run a script myscript.sh but get a "Permission denied" error. Which command fixes this issue?
medium
A. chmod -x myscript.sh
B. chmod +r myscript.sh
C. chmod +x myscript.sh
D. chmod 000 myscript.sh
Solution
Step 1: Identify cause of "Permission denied"
The error usually means the script lacks execute permission.
Step 2: Add execute permission
Using chmod +x myscript.sh adds execute rights, allowing the script to run.
Final Answer:
chmod +x myscript.sh -> Option C
Quick Check:
Add execute permission to fix "Permission denied" [OK]
Hint: Add execute permission with chmod +x [OK]
Common Mistakes:
Using -x which removes execute permission
Setting permissions to 000 which denies all access
Adding only read permission (+r) which doesn't allow execution
5. You have a script deploy.sh that you want to run directly by typing ./deploy.sh. However, it still says "Permission denied" after chmod +x deploy.sh. What could be the reason?
hard
A. The script is on a mounted filesystem that does not support execute permissions.
B. You forgot to add read permission with chmod +r deploy.sh.
C. You need to rename the script to deploy.exe.
D. You must run the script with bash deploy.sh instead of ./deploy.sh.
Solution
Step 1: Confirm execute permission is set
Since chmod +x deploy.sh was run, the script should have execute permission.
Step 2: Consider filesystem limitations
Some mounted filesystems (like FAT32 or network shares) do not support Unix execute permissions, causing "Permission denied" despite chmod +x.
Step 3: Evaluate other options
Adding read permission is usually default; renaming to .exe is irrelevant in Linux; running with bash works but does not explain the permission error when running ./deploy.sh.
Final Answer:
The script is on a mounted filesystem that does not support execute permissions. -> Option A
Quick Check:
Filesystem may block execute permission despite chmod [OK]
Hint: Check if filesystem supports execute permissions [OK]
Common Mistakes:
Assuming chmod always works on all filesystems
Thinking read permission alone allows execution
Confusing script name extension with execution ability
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.