Syntax error: "done" unexpected when trying to run shell script

2131 views linux
7

The code

#!/bin/sh
while true
do
  mpc current > current_song.txt
  mpc idle player
done

is resulting in

Syntax error: "done" unexpected

Any reason why it would be showing done as unexpected?

answered question

Change /bin/sh to /bin/bash

1 Answer

9

You're missing the brackets on the condition.

#!/bin/sh
while [ true ]
do
  mpc current > current_song.txt
  mpc idle player
done

posted this

Have an answer?

JD

Please login first before posting an answer.