18
5
So I've written my first bash script:
#!/bin/bash
echo 'hello world!'
exit
I know it has the right location to bash and is executable:
$ which bash
/bin/bash
$ chmod +x myscript.sh
Now I want to run it from the command line, but I get an error:
$ myscript.sh
myscript.sh: command not found
So instead I try this and it works:
$ bash myscript.sh
hello world!
Is this how I will always need to execute it? I feel like I have executed other scripts without having to precede it with bash
. How can I run myscript.sh without having to precede it with bash
?
Update: Here is a good explanation of why and how to execute a bash script.
I have already done that with chmod +x myscript.sh. Did I do it wrong? – Andrew – 2009-12-12T19:28:16.747
1You are probably missing ./ I've added it to the answer. – pupeno – 2009-12-12T19:30:06.010