linux how to execute script

Answer

There are many ways how to execute a script, the first one is execute 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 interpreter you can use sh, ksh, csh, bash etc.

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

chmod +x script.sh

Then you can execute script following way:

./script.sh

Another way how to run script:

source script.sh

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

Was this information helpful to you? You have the power to keep it alive.
Each donated € will be spent on running and expanding this page about UNIX Shell.