views:

84

answers:

5

ok I am writing my first bash script in ubuntu 10.04.

The file is on my desktop: /home/myuser/Desktop

The file is called hello-world

The file contains:

#!/bin/bash
echo "Hello World"

I open a command line and run:

/home/myuser/Desktop/hello-world

It tells me permition is denied. So I run it again with sudo, it asks me for my password, I type it in, hit return.

I get this output.

sudo: /home/myuser/Desktop/hello-world: command not found

What am I doing wrong?

+2  A: 

chmod +x hello-world

Nicolas Viennot
Thank you! ......(filler text)
John Isaacks
+3  A: 

Your script probably is not set to be executable. Try:

chmod u+x /home/myuser/Desktop/hello-world
Peter Jaric
+2  A: 

You need to mark the script as executable. Run chmod +x hello-world to add the executable bit.

Michael Madsen
+1  A: 

You can also do:

sh /home/myuser/Desktop/hello-world

which will execute the script without it needing to be set as executable.

Jonathan
Shouldn't that be `bash /home/myuser/Desktop/hello-world` to conform to the OP's choice of shell?
Peter Jaric
+3  A: 

If your script is called test.sh then do the following...

$ chmod +x test.sh

followed by

$ ./test.sh

Mad Gibberish