-1
while true; do
    java -Xmx512M -jar spigot.jar
    echo 'Press any key to exit...'
    if read -r -N 1 -t 5; then
        break
    fi
done

I get this error:

./start.sh: line 7: syntax error near unexpected token `done'
./start.sh: line 7: `done'
  • I have Bash installed

  • This code run fine in another computer

  • 2
    Are you sure you're using the right shell ? Do you have a [shebang line](https://stackoverflow.com/a/10383546/253056) ? – Paul R May 30 '17 at 13:34
  • How do you start your script? If i run it by my own, it Looks good – Jens May 30 '17 at 13:34
  • 4
    Any chance you copied it from a Windoze machine, and it has weird line endings? – Jack May 30 '17 at 13:36
  • Are there any weird characters between the `while true;` and the `do`? I can reproduce your error by omitting the "`do`". – cdarke May 30 '17 at 13:38
  • To make sure you're running the script with bash, either add `#!/bin/bash` as the top line or execute it by sourcing it `. myscript.sh` where myscript.sh is the name of your script – Jim U May 30 '17 at 13:40
  • I use ./start.sh to start my script – TheBlueKingLP May 30 '17 at 13:41
  • 2
    Try running the script with `bash -x start.sh`, that should give a trace of the shell expansions and ensure it is running under bash. – cdarke May 30 '17 at 13:46
  • same result.... – TheBlueKingLP May 30 '17 at 13:52
  • It looks alright, my test omits the java call line and runs fine, like he says use the bash -x test.sh option – Calvin Taylor May 30 '17 at 13:56
  • Your code works fine for me (with a dummy command substituted for your `java` command). I'm therefore inclined to guess that there's something weird about your local copy of the script. @Jack suggests one form that could take. It's short; how about just rewriting it, in a new file, with a local text editor? – John Bollinger May 30 '17 at 13:58
  • after re code still not working – TheBlueKingLP May 30 '17 at 14:16
  • I find out that the problem is the while true; do loop doesn't working,but why? – TheBlueKingLP May 30 '17 at 14:25
  • 1
    do `xxd < script` and post the result in your question. – 123 May 30 '17 at 14:30
  • Please edit your question instead of adding comments. Most comments are not shown initially. Make it easy for others to help you. – Robert Nov 03 '17 at 16:56

1 Answers1

0

found out why,because i make that file in a windows computer,the file is msdos format,so it isn't working