0
0
Bash Scriptingscripting~5 mins

Making scripts executable (chmod +x) in Bash Scripting - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the command chmod +x script.sh do?
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
Which command shows if a file is executable?
Als -l filename
Bcat filename
Crm filename
Dtouch filename
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
What permission does chmod +x add?
ARead permission
BWrite permission
CDelete permission
DExecute permission
What error appears if you run a script without execute permission?
ASyntax error
BFile not found
CPermission denied
DCommand not found
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.