Lessons · Terminal · making a file runnable
Permissions, and making a script runnable
ls -l shows three groups of r, w and x: owner, group, others. chmod +x adds the execute bit, which is what lets ./script.sh run.
Hone is a place to practise programming. This is one of its lessons, written out in full and free to read without an account.
What it is for
'Permission denied' on your own script is the first wall every beginner hits. It is one command away.
How to think about it
Read the ten characters: a dash or d, then rwx for you, rwx for your group, rwx for everyone. Add x to run, never add w for everyone.
Worked example
printf '#!/usr/bin/env bash\necho "hi from the script"\n' > hi.shA two-line script.
chmod 644 hi.shOwner reads and writes, others read.
ls -l hi.sh | cut -c1-10-rw-r--r--: no x anywhere.
./hi.sh 2>/dev/null || echo "not executable yet"The system refuses to run it.
chmod +x hi.shAdd the execute bit.
ls -l hi.sh | cut -c1-10-rwxr-xr-x.
./hi.shhi from the script.
Your turn
Make deploy.sh runnable.
chmod deploy.sh
Try it at a real prompt
The trap
chmod 777 to make an error go away. It gives everyone on the machine write access; +x was all that was needed.
Practise making a file runnable on HoneA question on it now, a coding challenge where there is one, and it is remembered for review. Free, no email needed.