Quote:
|
Originally Posted by carl0ski
i always seem to prefer for
for filename in `ls *img | sort -n | head -n 10`
do echo moving $filename
mv $filename directory
done
|
Just for the sake of completeness I'll say what are the difference (advantage / disadvantages) of both of them.
My one-liner solution is more practical if you just want to use it in the shell and may want to change it often. Since you can write in a single command line, its easy to modify and re-execute. On the other hand, if you want to do more than just a
mv it will get ofuscated and hard to use very quickly. So, it is good if you have simple commands in your while loop.
carl0ski idea of writing a for instead of a while, is better if you want to end up doing more complicated things. As you'll end up writting it in a file and then executing the script. I dont think it is very comfortable to use it directly in the shell (whenever you write a script in 4 lines, the shell is not so good at reediting that line).
Just some thoughts

Cheers!