3

我创建了一个 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

编辑:可能不是确切的行。我上次上传后改了

4

1 回答 1

11

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

用来dos2unix转换它。

于 2013-07-10T02:37:44.230 回答