11

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 CreateDB.py ./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: ./wtf.sh: /bin: bad interpreter: Permission denied

wtf.sh has executable rights.

What is wrong?

Jeff Schaller
  • 67,283
  • 35
  • 116
  • 255
Davlog
  • 323
  • 1
  • 4
  • 8

2 Answers2

12

You have a space instead of a forward slash here:

#! /bin bash

Should be:

#! /bin/bash

or simply

#!/bin/bash

(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.

goldilocks
  • 87,661
  • 30
  • 204
  • 262
  • 1
    You might want to get into the habit of using #!/bin/sh (instead of #!/bin/bash) unless you know that you are using bash features. – G-Man Says 'Reinstate Monica' Aug 11 '15 at 04:10
  • @G-Man Thanks for cleaning this up a bit. WRT bash vs. sh, I was just following the pattern from the question (although my tendency is to only use sh when I know I'm not using bash features). – goldilocks Aug 11 '15 at 08:53
  • In Ubuntu terminal, which bash is helpful. That returns /bin/bash. At the top of my Bash script I add #!/bin/bash. Then when I want to run the Bash script, I enter bash foo.sh. So which sh is used the same way. sh foo.sh – noobninja Jul 18 '16 at 09:26
  • 1
    @G-Man, in the workaday world there are an unfortunate number of people who don't know whether they are using Bash features or not. In many cases it's preferable to have a script not run at all (because Bash is specified in the shebang but is missing) rather than run and do something unexpected (because /bin/sh is something other than Bash and there are unnoticed Bashisms in the script). See here. – Wildcard Nov 23 '16 at 07:33
5

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).

Splud
  • 51
  • 1
    This is what did it for me. Just had to invoke the interpreter explicitly as said in this answer: bash ./myscript.sh – RyanQuey Mar 04 '23 at 14:32