I would like to pitchshift multiple audio files into multiple pitches, 12 for each file.

The following successfully pitchshifts one file:

sox *.wav Examples_100.wav pitch 100

And the following successfully converts all files in the directory from wav to mp3:

for f in *.wav; do sox "$f" "converted/${f%%.wav}.mp3"; done

I have tried to combine these commands to get the result I want. Here is my attempt to apply the pitch 100 command to all files in the directory.

for f in *.wav; do sox "$f" "converted/${f%%.wav}.wav” pitch 100; done

So first I need to solve this problem.

But eventually I would like the following applied to each file:

pitch 100
pitch 200
pitch 300
pitch 400
pitch 500
pitch 600
pitch -100
pitch -200
pitch -300
pitch -400
pitch -500
pitch -600

Therefore, each file in the directory would return 12 files in the output directory.

However, if you are able to help me solve the first problem, perhaps I can then solve the second myself.

Part 1 now solved.

Now I need to know why:

for f in *.wav; 
do sox "$f" "converted/${f%%.wav}.wav" pitch 100;
do sox "$f" "converted/${f%%.wav}.wav" pitch 200;

Runs the error:

-bash: syntax error near unexpected token `do'
  • Please explain what problem you are seeing when you run the command - it is not clear from your question.
    – QIS
    Aug 6, 2019 at 20:26
  • Nothing happens.
    – syntheso
    Aug 6, 2019 at 21:17
  • On closer look, it looks like your closing quote is a "smart quote", try replacing that with a standard quote. If you still have issues, try running set -x before your for loop and capture the output.
    – QIS
    Aug 6, 2019 at 22:17
  • Ah, well spotted! Thanks, this works now : ) I will move onto the second part
    – syntheso
    Aug 6, 2019 at 22:38
  • Struggling with part 2 now. Am I missing a semicolon or are there too many?
    – syntheso
    Aug 6, 2019 at 22:44

1 Answer 1


Use one (and only one) do statement per for loop, not one for each command run in the loop. e.g.

for f in *.wav; do
  sox "$f" "converted/${f%%.wav}.wav" pitch 100
  sox "$f" "converted/${f%%.wav}.wav" pitch 200


for f in *.wav; do
  for p in 100 200 300 400 500 600 -100 -200 -300 -400 -500 -600 ; do
    sox "$f" "converted/${f%%.wav}.$p.wav" pitch "$p"
  • If the OP's target is simply transposed MP3 files, then sox "$f" "converted/${f%.wav}.$p.mp3" pitch "$p" in the second loop would be better. Aug 7, 2019 at 8:19
  • @roaima possibly. i just copied the OP's sox command and adapted it so each pitch would have a separate file. i presume the OP can adapt it as required from there, and only needed a bit of help with how bash for loops work.
    – cas
    Aug 7, 2019 at 10:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .