syntax error near unexpected token `do' when run with sudo
问题 From here: http://www.sat.dundee.ac.uk/psc/watchdog/watchdog-testing.html for n in $(seq 1 60); do echo $n; sleep 1; sync; done I get: :~$ sudo for n in $(seq 1 60); do echo $n; sleep 1; sync; done bash: syntax error near unexpected token `do' 回答1: The shell parses the command line and because for looks like an argument to sudo , you basically get a do without a for . To fix it, run the loop in a subshell, either as a separate script, or like this; sudo sh -c 'for n in $(seq 1 60); do echo "