1

Replace dots with underscores in filenames, leaving extension intact

view story
linux-howto

http://unix.stackexchange.com – I have a bash script which I'm trying to get to replace dots in filenames and replace them with underscores, leaving the extension intact (I'm on Centos 6 btw). As you can see from the output below, the script works when there is a dot to replace, but in cases where the only dot is the extension, the script still tries to rename the file, instead of ignoring it. Can anyone point out how I should handle this better? Thanks for any help. My (faulty) script: #!/bin/bash for THISFILE in * do filename=${THISFILE%\.*} extension=${THISFILE##*\.} newname=${filename//./_} echo "mv $THISFILE (HowTos)