Can someone explain what is happening line by line in this script, particularly after the do statement. The script works, it renames all the files in my directory that has a date in the file name. But I would like to know more about it.
#!/bin/bash
newdate=12-10-1995
for file in *[0-9][0-9]-[0-9][0-9]-[0-9][0-9][0-9][0-9]*
do
mv $file ${file%[0-9][0-9]-[0-9][0-9]-[0-9][0-9][0-9][0-9].*}$newdate${file#*[0-9][0-9]-[0-9][0-9]-[0-9][0-9][0-9][0-9]}
done
It tries to rename any file with 2-2-4 digit date in the name and replace that date with a new date, but it contains an error as the dot should not be there.
It use parameter expansion to accomplish this.
newdate=12-10-1995
for file in *[0-9][0-9]-[0-9][0-9]-[0-9][0-9][0-9][0-9]*
do
mv "$file" "${file%[0-9][0-9]-[0-9][0-9]-[0-9][0-9][0-9][0-9]*}$newdate${file#*[0-9][0-9]-[0-9][0-9]-[0-9][0-9][0-9][0-9]}"
done