#!/bin/bash proc printHelp { echo "Usage: $0 -f find -r replace FILES_TO_RENAME*" echo -e "\t-f The text to find in the filename" echo -e "\t-r The text used to replace with in the filename" exit 1 } while getopts "f:r:" opt { match $opt { with r setglobal replace = $OPTARG with f setglobal fnd = $OPTARG with ? printHelp } } shift $shExpr(' $OPTIND - 1 ') if test -z $replace || test -z $fnd { echo "Need a string to find and a string to replace"; printHelp } for i in [$ifsjoin(Argv)] { setglobal newname = $[echo $i | sed "s/$fnd/$replace/] mv $i $newname echo "Renamed file $i to $newname" }