Linux bash sh - 找不到命令

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10852660/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 06:37:26  来源:igfitidea点击:

bash sh - command not found

linuxbash

提问by membersound

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

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

当我运行./build.sh表单命令行时,它说:

: command not found

And nothing happens. How can I solve this ?

什么也没有发生。我该如何解决这个问题?

采纳答案by Shahbaz

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. Since the script finishes, though, it reads an empty command, which it can't execute.

;是命令的分隔符。由于您的最后一个命令以 结尾;,因此您的 bash 可能需要另一个命令。但是,由于脚本完成后,它会读取一个无法执行的空命令。

回答by KurzedMetal

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

回答by laz4

I solved adding execute permissions:

我解决了添加执行权限:

sudo chmod +x file.sh

sudo chmod +x file.sh

回答by Vijendra patidar

I Have resolved my error from this command.

我已经解决了这个命令的错误。

sudo chmod +x build.sh

回答by ellooku

None of the above worked for me except

以上都不适合我,除了

sudo ./build.sh