2016-07-27 164 views
0

因此,我將位於桌面上的「colors.sh」格式化爲名爲notepad的文件。嘗試使用運行它:爲什麼我的.sh文件沒有在終端中運行?

./colors.sh 

,然後它說這個....

[email protected]:~$ cd Desktop/notepad/ 
    [email protected]:~/Desktop/notepad$ ll 
    total 144 
    drwx------ 2 shell shell 4096 Apr 9 2015 ./ 
    drwxr-xr-x 11 shell shell 4096 Jul 27 19:42 ../ 
    -rw-r--r-- 1 shell shell 35551 Oct 7 2014 colors background.PNG 
    -rwxr-xr-x 1 shell shell 2534 Apr 9 2015 colors.bat~* 
    -rw-r--r-- 1 shell shell 31047 Oct 7 2014 colors.PNG 
    -rwxr-xr-x 1 shell shell 2475 Apr 9 2015 colors.sh* 
    -rwxr-xr-x 1 shell shell 2475 Apr 9 2015 colors.sh~* 
    -rw-r--r-- 1 shell shell 1142 Aug 22 2013 Command Prompt.lnk 
    -rw-r--r-- 1 shell shell 84 Nov 21 2014 desktop.ini 
    -rwxr-xr-x 1 shell shell 92 Nov 21 2014 hello.bat* 
    -rw-r--r-- 1 shell shell 3755 Oct 16 2014 netstat.PNG 
    -rw-r--r-- 1 shell shell 1158 Aug 22 2013 Notepad.lnk 
    -rw-r--r-- 1 shell shell 970 Nov 18 2014 NSIS.lnk 
    -rwxr-xr-x 1 shell shell 504 Nov 21 2014 rainbow.bat* 
    -rwxr-xr-x 1 shell shell 31 Nov 21 2014 random.bat* 
    -rwxr-xr-x 1 shell shell 561 Oct 7 2014 spanish.bat* 
    -rw-r--r-- 1 shell shell 687 Oct 6 2014 text to speech.vbs 
    -rwxr-xr-x 1 shell shell 50 Oct 12 2014 timer.bat* 
    -rw-r--r-- 1 shell shell 2060 Feb 13 2013 Turbo C++.lnk 
    -rw-r--r-- 1 shell shell 182 Sep 23 2014 welcome dif.vbs 
    -rw-r--r-- 1 shell shell 2472 Sep 22 2014 welcome - Shortcut.lnk 
    [email protected]:~/Desktop/notepad$ chmod +x colors.sh 
    [email protected]:~/Desktop/notepad$ ./colors.sh 
    bash: ./colors.sh: /bin/sh^M: bad interpreter: No such file or directory 
+0

也許問題是* in *'colors.sh'? –

+1

使用不同的文本編輯器。在文件第一行('#!/ bin/sh')的行字符結束之前,你有一個流浪回車('^ M')。可能文件的每一行都有相同的問題。 –

+0

哦。好點子!老實說,甚至沒有想到這一點 – Shell

回答

2

錯誤消息的^M告訴所有:你的文本文件已被存儲爲「DOS」文本格式,即CR + LF行結束。 U * x解釋器單獨使用LF(^J)字符作爲行終止符,因此多餘的CR(^M)字符被附加到/bin/sh shell聲明中,因此使其無效。

保存您的文件與Unix/Linux行結束(LF)或轉換之前使用的dos到unix轉換器。

相關問題