Linux How to Execute Script

Linux How to Execute Script

There are many ways how to execute a script, the first one is to execute the script by specifying the interpreter:

bash script.sh
sh script.sh

For debugging use option “-x” to see what is being done.

bash -x script.sh

As an interpreter, you can use sh, ksh, csh, bash etc.

If you want to execute the script without specifying an interpreter, you need to set execute (+x) permission:

chmod +x script.sh

Then you can execute the script following way:

./script.sh

Another way how to run the script:

source script.sh

The script doesn’t need to execute permission in this example. If the script makes any changes to the environment, it will be visible after running the script, because commands in the script are executed in the current shell.

Leave a Comment