[clug] Help with bash script

Rob Bolin rob at unigon.tv
Fri Oct 31 23:49:17 GMT 2008


Hi all,

On the basis that "when all you have is a hammer, everything looks like a 
nail", I wrote a simple bash script to move mp3 files from one folder into n 
subfolders, file 1 into subfolder 1 ... file n into subfolder n, file n+1 
into subfolder 1 etc. It's a simple idea, easily implemented, unless some of 
the mp3 files include characters that need escaping (space, ampersand, 
parentheses etc). My simple script goes pear-shaped fairly quickly and google 
in *not* my friend today :-(

Can anyone suggest a fix for escaping these characters out in a script? My 
script follows.

Thanks in advance
Rob

#!/bin/bash
i=1
for file in *.mp3
do
    mv ${file} ${i}
    if  [ $i -eq 10 ]
        then i=1
        else i=$[${i}+1]
    fi
done

-- 
"Human errors can only be avoided if one can avoid the use of humans"
    -- Parnas and Clements "A Rational Design Process: How and Why to Fake it"


More information about the linux mailing list