20

I'm trying to execute a bash script (git-ftp) but I can't seem to do it. This is what happens:

[trusktr@rocketship ~]$ ~/scripts/git-ftp
: No such file or directory

The file has permissions 755.

This is the contents of the script: http://pastie.org/3567556

Why am I getting this error? What can I do to fix the problem?

trusktr
  • 44,284
  • 53
  • 191
  • 263
  • Does `ls ~/scripts/git-ftp` work? – kev Mar 11 '12 at 00:47
  • If you're like me, after reading the answer to this question you might want to look at [How line ending conversions work with git core.autocrlf between different operating systems](http://stackoverflow.com/q/3206843/1157054). – Ajedi32 Aug 24 '15 at 16:07

2 Answers2

38

I have seen this error if the script has windows line endings instead of unix line endings. Try running dos2unix on the script and see if you get the same error.

joesdiner
  • 1,125
  • 9
  • 11
  • 1
    Wow, interesting. That was exactly it. – trusktr Mar 11 '12 at 00:47
  • You mean that exact error with the colon: : no such file or directory. Makes sense; an empty command. It's not actually empty but the string `"\r"` The leading carriage return disappears when printed since on your Unix terminal it just moves the cursor to column 0. – Kaz Mar 11 '12 at 00:58
  • 3
    @Kaz: It's more complicated than that. The shebang line in the script is `#!/usr/bin/env bash\r`, so env prints the error "env: bash\r: No such file or directory". The carriage return makes the second part (": No such file or directory") overwrite the first part, so you don't see the first part. (p.s.: well spotted, joesdiner.) – Gordon Davisson Mar 11 '12 at 01:30
1

Is there a #! (hash bang) line in the script, and does the pathname resolve?

If the script is running, it may be something in the script. Add this command to the top of the script, before any other command (but of course after the hash bang, if there is one):

set -x   # enable trace mode
Kaz
  • 55,781
  • 9
  • 100
  • 149
  • Yeah, if you look at the script, it has "#!/usr/bin/env bash" at the top. I tried adding `set -x` but nothing new happens. – trusktr Mar 11 '12 at 00:34
  • Try `bash -x ~/scripts/git-ftp` and see if that reveals anything. FWIW the script runs fine for me printing the usage message – Perry Mar 11 '12 at 00:41
  • Thanks for trying to help me. Turns out @joesdiner was exactly right: I needed to convert all line endings to unix style. – trusktr Mar 11 '12 at 00:47