21
#!/bin/bash
cd ~/workspace/trunk;
svn up;

When I run ./build.sh form command line, it says:

: command not found

And nothing happens. How can I solve this ?

perror
  • 7,071
  • 16
  • 58
  • 85
membersound
  • 81,582
  • 193
  • 585
  • 1,120

5 Answers5

56

I solved adding execute permissions:

sudo chmod +x file.sh

laz4
  • 579
  • 4
  • 2
18

I Have resolved my error from this command.

sudo chmod +x build.sh
Vijendra patidar
  • 1,444
  • 1
  • 14
  • 24
15

My guess is that you have unprintable control characters in the file, or it has \r\n (CRLF) line endings (dos/windows mode).

Try checking it with these commands:

$ hexdump -C build.sh 
00000000  23 21 2f 62 69 6e 2f 62  61 73 68 0a 63 64 20 7e  |#!/bin/bash.cd ~|
00000010  2f 77 6f 72 6b 73 70 61  63 65 2f 74 72 75 6e 6b  |/workspace/trunk|
00000020  3b 0a 73 76 6e 20 75 70  3b 0a                    |;.svn up;.|
0000002a

$ file build.sh 
build.sh: Bourne-Again shell script, ASCII text executable

$ unix2dos build.sh 
unix2dos: converting file build.sh to DOS format ...

$ hexdump -C build.sh 
00000000  23 21 2f 62 69 6e 2f 62  61 73 68 0d 0a 63 64 20  |#!/bin/bash..cd |
00000010  7e 2f 77 6f 72 6b 73 70  61 63 65 2f 74 72 75 6e  |~/workspace/trun|
00000020  6b 3b 0d 0a 73 76 6e 20  75 70 3b 0d 0a           |k;..svn up;..|
0000002d

$ file build.sh 
build.sh: Bourne-Again shell script, ASCII text executable, with CRLF line terminators
KurzedMetal
  • 12,540
  • 6
  • 39
  • 65
11

None of the above worked for me except

sudo ./build.sh
ellooku
  • 161
  • 2
  • 11
7

Remove ; from the end of your script lines.

This doesn't happen in my bash, so I'm not sure what exactly is wrong, but my guess is this:

; is a separator of commands. Since your last command ends in ;, your bash probably expects another command after. Since the script finishes, though, it reads an empty command, which it can't execute.

Shahbaz
  • 46,337
  • 19
  • 116
  • 182
  • 3
    While the semicolons are unnecessary, they don't actually cause the issue given here -- worst-case you'd get a syntax error if you had two command-terminating sigils next to each other. – Charles Duffy Jun 01 '12 at 15:30
  • @CharlesDuffy, probably. However, I don't know what bash the OP is using. Since the error didn't happen in my bash, my guess is that his version is different, possibly expecting something to come after `;`. The error message indicates `: command not found` which implies his bash does in fact try to execute ``! – Shahbaz Jun 01 '12 at 15:35
  • 1
    Not necessarily `` -- more likely, it's trying to execute `$'\r'`, which simply _renders_ as nothing. – Charles Duffy Jun 01 '12 at 16:00
  • @DennisWilliamson, no the error message is enclosed in double quotes, most probably by the OP. There is one `"` in the end of the message also! – Shahbaz Jun 01 '12 at 16:44
  • This answer is simply wrong. When a script uses normal (UNIX-format) line endings, trailing `;`s are harmless -- you can easily test this yourself. It's only DOS line-endings that make this error trigger. – Charles Duffy May 07 '15 at 19:44