6.4 Execute a BASH script

We have discussed three approaches on how to write BASH code to a file. Let’s now see on how to launch the BASH script!

A script can be executed by calling its name

$ ./test.sh
bash: line 1: ./test.sh: Permission denied

We get a “permission denied” error, since for security reasons, no one has the right to execute a file on Unix by default. We can see the permissions for a files (and directories) by typing

$ ls -l test.sh
-rw-rw-r-- 1 phaentu phaentu 31 Okt 14 17:50 test.sh

Nine columns appear. Those represent the following:

  1. column: the file type and the file permissions.
  2. column: the number of memory blocks.
  3. column: the user (the one who has administrating power).
  4. column: the group of the user.
  5. column: the file size.
  6. column: the month the file/directory was last modified.
  7. column: the day the file/directory was last modified.
  8. column: the time the file/directory was last modified.
  9. column: the name of the file or the directory.