bash script,one liner, for filenames containing space

Good evening, everyone reading this.
I have a problem with bash scripting with spaces in file name. I want to (in this example) to convert 128 kbit mp3 files to 32 kbit, but it is not specific to this example…

i=0 ; for file in * ; do 'nice -'$((( ${i} % 18 ) + 1))' lame --silent --mp3input -a -q 0 --resample 22050 -b 32 \"'${file}'\" \"~/'${file}'\" \&' ; i=$* ; done

The problem occurs when the script executes the lame command and reaches the input file parameter containing space.
Error code for file “1113 - Den döende detektiven.mp3” :

If 'nice -3 lame --silent --mp3input -a -q 0 --resample 22050 -b 32 \"1113' is not a typo you can use command-not-found to lookup the package that contains it, like this:
    cnf nice -3 lame --silent --mp3input -a -q 0 --resample 22050 -b 32 \"1113

Is the problem " (double quote, or what’s it calles) (different between different coding, tested with UTF-8 and ISO 8859-1, same error) or is it my scripting that’s stop into error message.
If I put an ‘echo’ in the beginning, just printing it to console the command and copy-paste it back to console, it works well (below), but not directly.
echo to console :

i=0 ; for file in * ; do echo 'nice -'$((( ${i} % 18 ) + 1))' lame --silent --mp3input -a -q 0 --resample 22050 -b 32 \"'${file}'\" \"~/'${file}'\" \&' ; i=$* ; done

It is not the lame commando that is the problem. The problem is that around " I think, but what?
[edit] System openSUSE 12.2 KDE 4.8.5**

Your statement is a bit long and not easy to decipher. Couldn’t we work with an easier version?

To bein with I created this:

henk@boven:~/test> ls -l
totaal 4
-rw-r--r-- 1 henk wij 21 11 mrt 21:38 aap noot
henk@boven:~/test> cat aap\ noot
This is the contents
henk@boven:~/test>

A file with a blank space in the file name and it has some contents.

The following:

henk@boven:~/test> for f in a* ; do cat ${f}; done
cat: aap: Bestand of map bestaat niet
cat: noot: Bestand of map bestaat niet
henk@boven:~/test>

shows how bash offers two arguments to cat ad those do not exist.

Your construct, in your first trial (if I interprete that correct):

henk@boven:~/test> for f in a* ; do cat \"'${f}'\"; done
cat: "${f}": Bestand of map bestaat niet
henk@boven:~/test>

offers a very complicated (but wrong) argument to cat because the single quote escape prevents the $ from intrepretation and it adds the double quotes to the argument because they are also escaped.

What looks very obvious and simple to me:

henk@boven:~/test> for f in a* ; do cat "$f"; done
This is the contents
henk@boven:~/test>

and that works as expected and wanted.

Or do I misinterprete your problem completely?

Thanks hcvv :), that information instructs me how to implement it, great work of you. Now I just have to undestand how to add a ‘&’ at the end of command so things can run in parallel :slight_smile: Thanks to you it works now, the resulting one line command become

i=0 ; for fil in * ; do nice -$((( ${i} % 18 ) + 1)) lame --silent --mp3input -a -q 0 --resample 22050 -b 32 "$fil" "/home/quinness/$fil" ; i=$* ; done
i=0 ; for fil in * ; do nice -$((( ${i} % 18 ) + 1)) lame --silent  --mp3input -a -q 0 --resample 22050 -b 32 "$fil" "/home/quinness/$fil" & i=$* ; done

The & (in this context) is a list separator, like ;.

Try to read the bash man page. Searching through it for the usage of & must end up with what I explain here.**