model 14 wrote: ↑Thu Oct 17, 2019 9:17 pm
When I run the following from the terminal of Raspbian in my Pi 4B I get a "syntax error near unexpected token 'do'":
sudo for f in *.flac; do ffmpeg -i "$f" "${f%.flac}.wav"; done
rm *.flac
This batch file statement comes from the GPIO Music Box example. Its purpose is to convert .flac files to .wav.
Any help is appreciated. Thanks.
Get rid of the
sudo at the start, there shouldn't be any reason to run that line as root.
As to why you get a syntax error,
sudo takes the first argument as a command to run and the the rest up to the semi-colon (end of current command) as its arguments.
for is not a command that
sudo can run, it is a bash internal. Bash never sees the
for as a loop construct since it was an argument to
sudo so when it sees the next command,
do, it throws an error because
do isn't valid without (in this case) a corresponding
for.