简体   繁体   English

bash sh - 找不到命令

[英]bash sh - command not found

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

When I run ./build.sh form command line, it says: 当我运行./build.sh表单命令行时,它说:

: command not found

And nothing happens. 没有任何反应。 How can I solve this ? 我怎么解决这个问题?

我解决了添加执行权限:

sudo chmod +x file.sh

My guess is that you have unprintable control characters in the file, or it has \\r\\n (CRLF) line endings (dos/windows mode). 我的猜测是你在文件中有不可打印的控制字符,或者它有\\r\\n (CRLF)行结尾(dos / windows模式)。

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

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: 这不会发生在我的bash中,所以我不确定到底出了什么问题,但我的猜测是这样的:

; is a separator of commands. 是命令的分隔符。 Since your last command ends in ; 因为你的上一个命令结束了; , your bash probably expects another command after. ,你的bash可能需要另一个命令。 Since the script finishes, though, it reads an empty command, which it can't execute. 但是,由于脚本完成,它会读取一个无法执行的空命令。

我已从此命令解决了我的错误。

sudo chmod +x build.sh

以上都不适用于我,除非

sudo ./build.sh

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM