Lucky Leavell wrote:
OK, here is my complete scipt which runs under bash on an Ubuntu 6.06 system where I have the mp32ogg utility to convert mp3 to ogg files which k3b can handle:
for i in *.mp3 do echo $i mp32ogg $i done
whch works fine if the only craziness is embedded spaces in the file name; it failed when there were parentheses but, since that is rare in my situation, I can live with it. (Of course, if the single quoted $i would work there ... I'm off to try it!)
You need to use double quotes: In double quotes, shell variables are expanded, i.e., their value is inserted. In single quotes, variables are not expanded. The correct version of your script is: for i in *.mp3 do echo "$i" mp32ogg "$i" done Some might argue that the double quotes at echo are superfluous; but they are not: They are proper shell programming. If there is a file with two spaces in it, it is now output the proper way; otherwise the two spaces would have been turned into one space. The lesson: If you have a shall variable and pass it as an argument to a command, ALWAYS include it in double quotes UNLESS if you want the value broken along its white space. Everything else is sloppy programming and might bite you some time in the future. You can do that in interactive usage, but refrain from it in shell scripts. Oh yes, and within quotes, shell wildcards are not expanded. Therefore you must not put any quotes around *.mp3, as some posters did it. Joachim (who wrote his first shell script in the mid-80s :-) ----- PS: And something fitting from my quote collection. [You can find the reference on Google Groups. :-)] From: Larry Wall Drew Mills writes: : A contest to see who could write the most useful script that could : actually be used in the most languages *as is* [...] I've written some scripts that work in 582 different languages, all of them named sh. -- =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- Joachim Schrod Email: jschrod@acm.org Roedermark, Germany