Sox Batching Process under Debian

I want to reprogram a bunch of wav files I got in a folder.

My script:

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

      

The console will give me this error: "sox FAIL formats: cannot open input file" 90.wav "': no ​​such file or directory", etc. with 300 files that go into this folder.

How can I batch process these files? Why is it giving me this error?

Thank you so much!

Decision:

for i in *wav; do echo $i; sox $i -r 48000 ${i%%.wav}r.wav; done

      

+3


source to share


1 answer


Summary: These are quote characters

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 the shell to handle the shell correctly, the standard ASCII quote character must be used:

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

      

Note that it ${f%%%.wav}

removes any occurrences %.wav

from the end of the input file name. ${f%%%.wav}.wav

adds one .wav

back to the end after removing any suffixes %.wav

. You probably want something else here.

Check



Using bad quote characters, as per the question, please note 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 that the filename in the error message appears with two sets of quotes around the filename. This is what you saw from the error message in the question. Outer single quotes are provided sox

. Inner double quotes are funny quote characters provided on the command line. Since they are non-standard characters, the shell left them in place and passed them on to the command sox

.

As long as the file 90.wav

exists, the file named "90.wav"

does not exist. Hence the error.

Conclusion

Stick to standard ASCII characters for shell commands.

This problem can be easily realized if shell commands are typed using a fancy word processing editor that replaces typographic but non-standard characters. As three times points out, this can also happen when copying and pasting from websites with inappropriate typographic style.

+3


source







All Articles