unix bash语法错误附近意外令牌'do'

时间:2013-07-10 02:31:33

标签: bash ubuntu

我创建了一个unix minecraft发射器。它只在一个半小时前完成(截至9:30)。然后我明白了:

/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 个答案:

答案 0 :(得分:11)

我的猜测是您将脚本转换为Windows格式(可能是从Windows复制)然后您收到此错误:意外do\r,因为\r是意外的。

使用dos2unix进行转换。