0
0
Bash Scriptingscripting~20 mins

Making scripts executable (chmod +x) in Bash Scripting - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Executable Script Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
What is the output of this command sequence?
You have a script named myscript.sh without execute permission. You run these commands:

ls -l myscript.sh
chmod +x myscript.sh
ls -l myscript.sh

What changes will you see in the second ls -l output compared to the first?
Bash Scripting
ls -l myscript.sh
chmod +x myscript.sh
ls -l myscript.sh
AThe file permissions will show an 'x' for the user, group, and others indicating execute permission.
BThe file size will increase because execute permission adds bytes to the file.
CThe file owner will change to root after running chmod +x.
DThe file name will change to myscript.sh.exe after adding execute permission.
Attempts:
2 left
💡 Hint
Think about what the 'x' means in file permissions and what chmod +x does.
📝 Syntax
intermediate
1:30remaining
Which command correctly makes a script executable for the owner only?
You want to make a script named run.sh executable only by the file owner, not by group or others. Which command achieves this?
Achmod +x run.sh
Bchmod a+x run.sh
Cchmod u+x run.sh
Dchmod og+x run.sh
Attempts:
2 left
💡 Hint
Remember that 'u' means user (owner), 'g' group, 'o' others, and 'a' all.
🔧 Debug
advanced
2:30remaining
Why does this script fail to run even after chmod +x?
You have a script script.sh with execute permission set by chmod +x script.sh. When you run ./script.sh, you get bash: ./script.sh: /bin/bash^M: bad interpreter: No such file or directory. What is the cause?
AThe script is missing the .sh extension.
BThe script has Windows-style line endings causing the ^M character in the shebang line.
CThe script file is empty and cannot run.
DThe script does not have execute permission for the user.
Attempts:
2 left
💡 Hint
The ^M character often appears when files are edited on Windows and run on Linux.
🚀 Application
advanced
2:00remaining
How to make all scripts in a folder executable for the owner only?
You have many scripts in a folder scripts/. You want to make all files ending with .sh executable only by the owner. Which command will do this correctly?
Achmod +x scripts/*.sh
Bchmod a+x scripts/*.sh
Cchmod og+x scripts/*.sh
Dchmod u+x scripts/*.sh
Attempts:
2 left
💡 Hint
Think about which users should get execute permission and how to specify that in chmod.
🧠 Conceptual
expert
2:30remaining
What is the effect of chmod 4755 script.sh?
You run chmod 4755 script.sh on a script. What does the '4' in the permission number do?
AIt sets the setuid bit, causing the script to run with the file owner's permissions.
BIt sets the read permission for the owner only.
CIt sets the execute permission for group and others only.
DIt sets the sticky bit, preventing others from deleting the file.
Attempts:
2 left
💡 Hint
The first digit in chmod numeric mode sets special permissions like setuid, setgid, and sticky bit.