Sox batch process under Debian

bash, batch-processing, linux, sox

Solution

Summary: It is the quote symbols

The problem is with the double-quotes:

for f in *.wav; do sox “$f” -r 48000 “${f%%%.wav}.wav”; done

The double-quotes above are non-standard. For them to be properly processed by the shell, the standard ASCII quote symbol must be used:

for f in ./*.wav; do sox "$f" -r 48000 "${f%%%.wav}.wav"; done

As an aside, note that `${f%%%.wav}` removes any occurrences of `%.wav` from the end of the input file name. `${f%%%.wav}.wav` adds one `.wav` back on to the end after removing any `%.wav` suffixes. You likely want something else here.

Verification

Using the bad quote characters, as per the question, observe the error message:

$ for f in *.wav; do sox “$f” -r 48000 “${f%%%.wav}.wav”; done
sox FAIL formats: can't open input file `“90.wav”': No such file or directory

Note the file name in the error message is shown with two-sets of quotes around the file name. This is what you saw as per the error message that in the question. The outer single-quotes are supplied by `sox`. The inner double-quotes are the funny quote characters provided on the command line. Because they are non-standard characters, the shell left them in place and passed them to the `sox` command.

While the file `90.wav` exists, no file by the name of `“90.wav”` exists. Hence, the error.

Conclusion

Stick to standard ASCII characters for shell commands.

This issue can easily happen if the shell commands are typed in using a fancy word-processing editor that substitutes in typographically-pretty but non-standard characters. As tripleee points out, it can also happen when copying-and-pasting from the websites with inappropriate typographical styling.

Problem

I want to resample a bunch of wav files that I got on a folder. My script is this: ``` for f in *.wav; do sox “$f” -r 48000 “${f%%%.wav}.wav”; done ``` The console give me this error: "sox FAIL formats: can't open input file `“90.wav”': No such file or directory" and so on with the 300 files that are placed on that folder. How can I batch processing right this files? Why is it giving me this error? Thanks a lot! Solution: ``` for i in *wav; do echo $i; sox $i -r 48000 ${i%%.wav}r.wav; done ```

Original source