Bash pattern matching
By tom on 22. November 2008 - 0:22
BASH offers a nice way to replace patterns. Until now I always used basename and a variable.
For example moving all .jpeg files in a folder to .jpg (hey, it's just an example..)
for moo in *.jpeg; do
newname="`basename $moo .jpeg`.jpg"
mv $moo $newname
doneBut isn't that just plain ugly? That one is lot nicer:
for i in *.jpeg; do
mv "$i" "${i%.*}.jpg"
done1337