-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 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,522
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.