-3

Hello I am lost sorry I dont know why my script wont run

my script is: echo "hi"

when i type: sudo ./my.sh

it shows: unable to excute my.sh: no such file or directory hangup

and when i type: ./my.sh

it shows: -bash: ./my.sh: bin/bash: bad interpreter: no such file or directory

it would be great if you can help me thank you very much

  • 2
    You've not provided any OS & release details; and your script doesn't have a *shebang* that tells the system what type of script it is, and what interpreter/shell to use to execute it with. Did you make it executable? – guiverc Dec 08 '21 at 10:30
  • 2
    It looks like your script is **not** just `echo "hi"`, but has a `#!` line - which is incorrectly written with a relative path `#!bin/bash` instead of absolute path `#!/bin/bash` – steeldriver Dec 08 '21 at 12:40
  • 1
    Does this answer your question? [bin/bash: bad interpreter: No such file or directory](https://askubuntu.com/questions/1158577/bin-bash-bad-interpreter-no-such-file-or-directory) – karel Dec 09 '21 at 03:17

2 Answers2

1

Three things:

  1. Why the sudo? At this point, you do not want to run your script as root.

  2. All your scripts need to start with the interpreter on the first line It's the comment sign followed by an exclamation sign. (The "Shebang") For bash, your script would look like this:

    #!/bin/bash

    echo "hi"

  3. You should make your scripts executable with chmod 700 myscript.sh. Only then can you execute them like this ./myscript.sh

On a related note, this is not specifically a Ubuntu question, but a generic scripting question.

jawtheshark
  • 2,482
  • 1
  • 17
  • 21
0

/usr/bin/bash $HOME/my.sh

Try this and see the difference, you probably are not in the right directory to execute a file. cd or pwd and ls to make sure what you are doing.

Sadaharu Wakisaka
  • 1,329
  • 1
  • 13
  • 25