↑↓ move Enter open Esc close

How to Run a Script in Linux (bash and ./script.sh)

Run Bash and executable scripts correctly using an interpreter, execute permissions and a shebang.

Linux gives you two common ways to run a script: pass it to its interpreter, or execute it directly with a valid shebang and execute permission.

Step by step

1 Run with Bash

$ bash script.sh

The file itself does not need execute permission when Bash reads it explicitly.

2 Make it executable

$ chmod +x script.sh

Adds execute permission without requiring world-write access.

3 Execute it directly

$ ./script.sh

The ./ prefix explicitly names the file in the current directory. A valid shebang should identify the interpreter.

4 Debug it

$ bash -x script.sh

Prints commands as Bash executes them.

Tips worth knowing

Frequently asked questions

Why do I need ./ before a script?

The current directory is normally not in PATH, so ./ explicitly names the local file.

Do I need chmod +x if I use bash script.sh?

No. Passing the file to Bash does not require the file itself to be executable.

Why do I get Permission denied?

The script may lack execute permission, a parent directory may block traversal, or the filesystem may use noexec.

If it goes wrong

The commands behind it

Concepts involved: File permissions

More how-to guides