I want to learn more so I have tried to script more than just using the terminal. I know rename
and I can rename image files with rename 's/ /_/g' *.jpg
but when I write it in a shell script to point at a directory:
DIRECTORY="/foo/bar"
for imgfile in $(find $DIRECTORY -type f -name *.jpg); do
echo 'replacing whitespace in' $(basename $imgfile)
rename -f 's/ /_/g' *.jpg
done
it doesn't work and the terminal will take a file (example: 1234 abcd.jpg
) and echo abcd.jpg
. So where am I going wrong?