Bash Script Permission denied & Bad Interpreter

I’m on a kali linux 64 bit.

I have created a python script which takes 2 arguments to start. I don’t want to type out every time the exact same paths or search in the history of the commands I used in terminal. So I decided to create a simple script which calls the python script with its arguments.

#! /bin bash

python ./WtfPath ./NoWtfPath/NewSystem/

It is the exact same command I would use in terminal. However, I get an error message when I try to execute the script file.

bash: ./ /bin: bad interpreter: Permission denied has executable rights.

What is wrong?

Asked By: Davlog


You have a space instead of a forward slash here:

#! /bin bash

Should be:

#! /bin/bash

or simply


(the first space is optional). 
The shebang (#!) should be followed by the path to an executable, which may be followed by one argument, e.g.,

#!/usr/bin/env sh

In this case /usr/bin/env is the executable; see man env for details.

Just /bin refers to a directory.

Answered By: goldilocks

It is worth noting that if the mountpoint on which your script resides has the ‘noexec’ attribute, then you can shebang all you want and it still won’t work, but invoking the interpreter with the script as an argument will (so long as that in turn doesn’t try to run another script on a noexec mount).

Answered By: Splud