This is my homebrew bash script for batch renaming files extensions (my music library needs organizing):#!/bin/bash# rext.sh# Syntax: rext.sh EXT1 EXT2# Batch rename any file in current directory with extension of EXT1 to EXT2EXT1=$1EXT2=$2for f in *.$EXT1do  fname=${f%.*}  newfname=$fname.$EXT2  mv -v -i $f $newfnamedoneIt works beautifully with my music files, but is this code sufficient or can I still improve on it? Also I've seen examples using rename instead of mv, so is there any advantage in using rename?
Bash script to batch rename files
beginner;bash
A tiny mistake is not quoting $EXT1 in for f in *.$EXT1.If it contains a space, the script won't work as expected.I agree it's an unrealistic corner case,but it's easy enough to protect against with proper quoting: for f in *.$EXT1.The rename Perl script is famous for this purpose.Since you asked about its advantages:Stood the test of timeYou don't have to write itIt has more features (full regex support)The equivalent usage to simulate the behavior of your script would be:rename -v 's/EXT1$/EXT2/' *.EXT1A feature I like is the -n flag for dry run, to verify the renames that would be performed before actually performing them.