1

I'm trying to convert one music files with format .gsm to format .wav. This is how I tried

for f in *.gsm; do sox $f new/${f%.wav}; done

The result is that I get the same files with the same format .gsm in the new/ directory.

Can anyone point what the problem is here?

1

${f%.wav} removes .wav from the end of the variable. Since f only ever contains filenames with .gsm at the end, ${f%.wav} outputs the filename unchanged.

You probably want "${f%.gsm}.wav" instead (assuming either (a) sox actually did convert the files and only the extension is incorrect or (b) sox uses the filenames to determine the conversion required, so fixing the filenames would fix the conversion).

  • Thanks for the help but if do it this way ${f%.gsm}.wav I got files with both extensions, like file.gsm.wav, file1.gsm.wav.. etc – S.I. Nov 14 '18 at 11:22
  • @S.I. huh, Try # instead of %. Either # removes a suffix and % a prefix, or vice versa. I always mix up those. – muru Nov 14 '18 at 12:00
  • I've tried it and still both extensions are there. – S.I. Nov 14 '18 at 12:11
  • @S.I. I cannot reproduce. ${f%.gsm}.wav correctly replaces the extension for me. – muru Nov 14 '18 at 23:18
  • Thanks for the help. I really don't have an idea what was the problem. After a restart of the machine and tried again now is removed the .gsm correctly. – S.I. Nov 15 '18 at 6:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.