簡體   English   中英

bash sh - 找不到命令

[英]bash sh - command not found

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

當我運行./build.sh表單命令行時,它說:

: command not found

沒有任何反應。 我怎么解決這個問題?

我解決了添加執行權限:

sudo chmod +x file.sh

我的猜測是你在文件中有不可打印的控制字符,或者它有\\r\\n (CRLF)行結尾(dos / windows模式)。

嘗試使用以下命令檢查它:

$ 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

刪除; 從腳本行的末尾開始。

這不會發生在我的bash中,所以我不確定到底出了什么問題,但我的猜測是這樣的:

; 是命令的分隔符。 因為你的上一個命令結束了; ,你的bash可能需要另一個命令。 但是,由於腳本完成,它會讀取一個無法執行的空命令。

我已從此命令解決了我的錯誤。

sudo chmod +x build.sh

以上都不適用於我,除非

sudo ./build.sh

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM