2013-07-10 91 views
3

我創建了一個unix minecraft啓動器。它在一個半小時前(截至9:30)完全正常工作。那麼我得到這個:在意外標記'do'附近出現unix bash語法錯誤

/home/axium1998/MinecraftMegaLauncher.sh: line 14: syntax error near unexpected token ~'$'do\r''. 
/home/Axium1998/MinecraftMegaLauncher.sh: line 14: 'do 

我不知道是什麼造成了這一點。

# If code needs to be changed, just send me a PM saying something like: Project:MinecraftMegaLauncher Line #<line number> = <changed code> 
# if it works (I bet it will, but for me to learn xP)it will be replaced/fixed. 
export mc=$HOME/.minecraft 
export mcB=$HOME/officialBackup 
export tekkit=$HOME/.technic 
export tekkitB=$HOME/tekkitBackup 
export ftb=$HOME/.feedthebeast 
export ftbB=$HOME/ftbBackup 
export options=("Official" "MagicLauncher" "Tekkit" "FTB" "Backup" "Restore" "Quit") 
echo "==========MinecraftMegaLauncher==========" 
echo "This currently supports the following launchers: Official, Magic, Tekkit, and FTB, and doing backups as well!" 
echo "I (AXIUM1998) am not responsible for data loss/corruption while backing up/restoring. (It is still indev)" 
echo "Also, if there is a launcher you want to be in this mega launcher, I will consider implementing them." 
echo "BUG: Running restore twice in a row (running restore, then running it again immeditely) will erase all mc data." 
cd $HOME 
select optL in "${options[@]}" 
do 
    case $optL in 
    "Official") 
     echo "Starting the Official launcher..." 
     java -jar minecraft.jar 
    ;; 
    "MagicLauncher") 
     echo "Starting the MagicLauncher..." 
     java -jar magic.jar 
    ;; 
    "Tekkit") 
     echo "Starting the Tekkit launcher..." 
     java -jar tekkit.jar 
    ;; 
    "FTB") 
     echo "Starting the FTB launcher..." 
     java -jar ftb.jar 
    ;; 
    "Quit") 
     echo "Quitting..." 
     break 
    ;; 
    "Backup") 
     echo "Starting the backup..." 
     echo "Please input your password (Admin needed :()" 
     sudo touch dv 
     sudo rm dv 
     if [ ! -d $mcB ]; then 
     sudo mkdir $HOME/officialBackup 
     fi 
     if [ ! -d $tekkitB ];then 
     sudo mkdir $HOME/tekkitBackup 
     fi 
     if [ ! -d $ftbB ]; then 
     sudo mkdir $HOME/ftbBackup 
     fi 
     cd $mcB 
     sudo rm -rf * 
     cd $tekkitB 
     sudo rm -rf * 
     cd $ftbB 
     sudo rm -rf * 
     sudo cp -R $mc/* $mcB/ 
     sudo cp -R $tekkit/* $tekkitB/ 
     sudo cp -R $ftb/* $ftbB/ 
     echo "Backup complete" 
     echo "Making current user owner of files..." 
     sudo chown -R $USER $mcB 
     sudo chown -R $USER $tekkitB 
     sudo chown -R $USER $ftbB 
     echo "User $USER now can write to backed up folders" 
    ;; 
    "Restore") 
     echo "Starting the restoration..." 
     echo "Admin is, again, required :(" 
     sudo touch dv 
     sudo rm dv 
     cd $mc 
     sudo rm -rf * 
     cd $tekkit 
     sudo rm -rf * 
     cd $ftb 
     sudo rm -rf * 
     cd $HOME 
     sudo mv $mcB/* $mc/ 
     sudo mv $tekkitB/* $tekkit/ 
     sudo mv $ftbB/* $ftb/ 
     echo "Restore complete" 
    ;; 
    *) 
     echo "Invalid operand.";; 
    esac  
done 

編輯:可能不是確切的路線。我最後上傳它後,我改變它

+1

嗨,你需要讓我們半途見面 - 將你的腳本剪下來,生成bug的最小版本並粘貼。 –

+0

通常在這裏發佈代碼 –

+0

代碼很棒!但是我們無法完成一個龐大的計劃。相反,請嘗試發佈[SSCCE](http://sscce.org/)。 –

回答

11

我瘋狂的猜測是,你的腳本轉換爲Windows格式(也許從Windows複製它),然後你收到此錯誤:意外do\r,因爲\r是意外的。使用dos2unix將其轉換。

+1

謝謝謝謝謝謝你!這解決了我的問題。雖然在查看代碼時,我注意到沒有區別,但明天醒來時我會再看一遍,但嚴重的是,thx! – AXIUM1998

+3

@ AXIUM1998:指出答案解決了您的問題的方法是接受它(單擊答案分數旁邊的複選標記)。請不要在標題中編輯「[solve]」(我已將其刪除)。 –

+0

@dtmilano嗨,我有類似的問題,並認爲這可能是解決方案,你會碰巧知道如何訪問'dos2unix'命令?我的終端說它找不到它:/ – thnkwthprtls

相關問題