Executing scripts

Make a script executable

In order to execute a script, the user must have a corresponding permission.

Check users permissions on the testScript:

ls -l <directory containing testScript>

For example, the output -rw-rw-r-- means that the file owner does not have permission to execute the file (the fourth symbol -). The seventh symbol is -, so the users from the group owning the file do not have permission to execute it. The tenth symbol is also -, which means that the other users (not the owner of the file and not the users from the group which owns the file) do not have permission to execute the file.

Make testScript executable by the file owner:

chmod u+x testScript

If we check the permissions now, we can see that the output has changed to -rwxrw-r--. The fourth symbol x means that the file owner can execute it.

Make the testScript executable by all users:

chmod +x testScript

Checking permissions shows -rwxrwxr-x. The seventh and the tenth symbols are x meaning that the user from the group owning the file, as well as other users can execute the file.

Execute ‘testScript’ file using the bash binary

bash -c "./testScript"

This way of executing files may be useful while working with Docker containers. For example, in order to execute ‘testScript’ file in a container:

docker exec <containerName> bash -c ". <somePath>/testScript"