Depends really on what you are attempting... I would suggest you run it from start to finish in your mind... Ignore the loop mentally...
Take the first file... think about what you want done to it and follow it along step by step.
I do know one thing... the below will cause issue:
r0cks0ul wrote:
Code:
ls *.rar |while read LINE
do
folder=${LINE%.par*.rar}
mkdir -p $folder
mv $LINE $folder
cd $folder
done
You don't want to cd to the folder (from here on out I will call it a directory, since that's *nix talk) while in the loop, unless you cd back out before the next iteration. Since it seems this portion is just a sorting... I would say you don't need to cd to the directory at all, but you might want to add the directory to a list to cd into later. In fact, you could avoid the system doing the same things over and over by separating the task a little more... like:
Code:
ls *.rar | cut -d. -f1 | sort -u | while read LINE
do
new_dir=${LINE}
echo ${new_dir} >> new_directory.lst
mkdir -p ${new_dir}
mv ${LINE}.* ${new_dir}/
done
The above gets all the prefixes at once, then goes down the list of those prefixes, adding their name to a file called "new_directory.lst" then making the folder and moving all files with that prefix to that new directory. The list was only made if you needed to go back later and go into each of those folders to do something else (like extract further). You would just have to iterate through the list, cd'ing to the directory, and executing a rar for each file in the directory.
You could also just do the further extraction while in the loop, you just have to make sure of your path while you work... like:
Code:
ls *.rar | cut -d. -f1 | sort -u | while read LINE
do
new_dir=${LINE}
# echo ${new_dir} >> new_directory.lst # don't really need this, but you can still use it to keep track for clean up...
mkdir -p ${new_dir}
mv ${LINE}.* ${new_dir}/
cd ${new_dir}
# do some extracting further...
# or not...
cd - # go back to the previous directory
done
As far as putting them together, it depends on what comes first. Again, just step through your goal from the start to the finish.
HTH