No Such File or Directory error

Hi! I just recently started messing around with Unix, but I've come upon one problem multiple times. Whenever I try to run a shell script, for example;

#! /bin/bash 
#-------------------------------------- 
# example1 
#-------------------------------------- 
echo "Hello, World!" 

I always get the error:

: No such file or directory

The file is in the correct directory, I've verified that with ls -l, I've also used chmod 700 example1, to give myself permissions to execute the shell, but I just keep getting the same problem. Thanks for any help!

As it is probably not in the path ensure......

Assuming it is executable:-

1) chmod 755 /full/path/to/filename.ext<CR>
2) use one of two methods to run it:-
A) /full/path/to/filename.ext<CR>
B) ./filename.ext<CR>
From the current directory/drawer/folder.
<CR> is the carriage return or enter key...

EDIT:
Note in your script the first line should read:-

#!/bin/bash

No space at all in the line.

Can you post what exactly you did?

Set xtrace / verbose and run your script and post the output.

#!/bin/bash -xv

As wisecracker said, current working directory will not be part of PATH and it is not supposed to be.

So execute your script like he posted.

It's not the spacing in the shebang.

$ echo $'#! /bin/bash\necho hello world\n' > file; chmod a+x file; ./file
hello world

But perhaps this: (Different OS/shell would produce different error. This is from Linux & Bash)

$ echo $'#! /bin/bash\r\necho hello world\n' > file; chmod a+x file; ./file
-bash: ./file: /bin/bash^M: bad interpreter: No such file or directory
$ sh
$ ./file
sh: 4: ./file: not found

Did you create the file in Windows? You need to remove the Windows line endings. This is just one of many ways:

tr -d '\r' < file > newfile

I created the file in Windows and then uploaded the file to a Unix timeshare.

Hi neutronscott et al...
Just for information purposes...
OSX 10.7.5 default bash terminal...

Last login: Sat Jan 25 09:46:55 on ttys000
AMIGA:barrywalker~> echo "text" > testtxt
AMIGA:barrywalker~> cd ..
AMIGA:barrywalker/Users> ./testtxt
-bash: ./testtxt: No such file or directory
AMIGA:barrywalker/Users> _