Execute a script

From Linux Shell Scripting Tutorial - A Beginner's handbook
Jump to: navigation, search
← Setting up permissions on a scriptHomeDebug a script →

A shell script can be executed using the following syntax:

chmod +x script.sh
./script.sh

You can also run the script directly as follows without setting the script execute permission:

bash script.sh
. script.sh

In last example, you are using . (dot) command (a.k.a., source) which reads and executes commands from filename in the current shell. If filename does not contain a slash, directory names in PATH are used to find the directory containing filename.

When a script is executed using either the bash command or the dot (.) command, you do not have to set executable permissions on script but read permissions need to be set.