0

On Ubuntu,

I've created an executable file for Ruby with

bin/hello (name of the file)

#!/usr/bin/env ruby

But whenever I run bin/hello from bin's parent directory

It comes up with : No such file or directory

I'm sure there isn't any typo or anything.

What could be wrong?

9
  • 1
    Can you provide a little more detail? The error message, for example, looks incomplete. Is there something before the colon (:) or is it really blank like that? Also, is the mode of the file bin/hello set to executable? Commented Aug 27, 2013 at 1:47
  • I ran chmod +x bin/hello and yes that's all the message I'm getting from shell Commented Aug 27, 2013 at 1:49
  • Does it work if you go to the bin directory and type, ruby hello? Or if you type, ./hello? Commented Aug 27, 2013 at 1:50
  • ruby hello is working but not ./hello Commented Aug 27, 2013 at 2:02
  • What shell is first in your $PATH? Commented Aug 27, 2013 at 2:58

2 Answers 2

1

I think it's most likely you saved the file with Windows newlines (CRLF); the invisible CR before the end of the first line causes the executable search to fail, and part of the error message "erases" itself due to the carriage return.

Look at the file in vim and see if ^M shows up at the end of lines. Alternately, you can look at the output of xxd bin/hello | head -n 10 and see if 0D 0A (CR LF) appears. If you suspect CRLF, you can use dos2unix to fix the file back to Unix (LF) newlines.

Sign up to request clarification or add additional context in comments.

2 Comments

You are absolutely right. The file was created using my text editor with remote FTP sync from my Windows 8 OS. I basically created the file from shell directly using vim and voila! It worked. Thanks a lot for your help!
I think this is a really good question and answer as a lot of Windows users might get affected by this if they create *nix executable files via text editor in a local environment
0

You have to make the file executable

chmod +x bin/hello

After that run it by writing

./bin/hello

2 Comments

chmod +x is not to make it writable, but executable.
The OP claimed in his comments that he had already done this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.