0

I have files Deep.flac and A1 - Rolling In The Deep.flac

I wrote the script below, however it can only work with Deep.flac It cannot seem to work with filenames with spaces. I am learning unix system though my OSX.

Basically, I am using sox to convert my flac to aiff while keeping the name of the files intact.

My Script convertX2Y.sh:

#!/bin/bash

# Author: Rei Yash Dean
# Copyright: Free
# Script: to convert flac files to aiff using sox; while keeping file name unchanged

for x in *.flac;
do sox $x $(basename $x .flac).aiff;
done

The error it returns is:

sox FAIL formats: can't open input file `The': No such file or directory
Rui F Ribeiro
  • 56,709
  • 26
  • 150
  • 232
Rei89
  • 9

1 Answers1

1

Put quotes around things you want to be treated as single arguments by the program:

sox "$x" "$(basename "$x" .flac).aiff"

If you use double quotes (like above) then you can use variable references like $x inside them. If you use single quotes ('...') then any special characters you use inside them are kept as you wrote them.

Michael Homer
  • 76,565