Score:-2

Bash Scripting problem

ru flag

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

guiverc avatar
cn flag
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?
hr flag
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`
karel avatar
sa flag
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)
Score:1
jp flag

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.

Yarin Levy avatar
ru flag
i did use Shebang sorry i didnt not mention. In addition i also gave the right permissions. Thank you for your answer
jp flag
Can you execute `whereis bash`?
pLumo avatar
in flag
Using `chmod +x` instead of `chmod 700` wouldn't affect read and write as well as group/other permissions
Score:0
pl flag

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

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.