Skip to content

The Execution Permission#

The most common thing you'll find yourself doing is setting a script/file to be executable, in my opinion: chmod +x script.py. Now you can do ./script.py and it'll (hopefully) execute.

Copy and paste the following to your terminal and we'll check the results out after the fact:

1
2
3
4
5
6
cat <<EOF > my_script
#!/bin/bash
echo "Hello, from inside of my_script"
EOF
chmod +x my_script
./my_script

After you copy/paste this, hit Enter to trigger the line ./my_script. I get this:

1
2
3
4
5
6
7
michael@develop:~$ cat <<EOF > my_script
> #!/bin/bash
> echo "Hello, from inside of my_script"
> EOF
michael@develop:~$ chmod +x my_script
michael@develop:~$ ./my_script
Hello, from inside of my_script

You just created an executable. Even though it was a plain file, it had two ingredients that made it an executable:

  1. It had the x permission
  2. It has a "bang" line: #!/bin/bash

We'll come to the bang line later. For now, the x permission is what interests us.

We know what it means, but I wanted you to create a script and see it in action.