#!/bin/bash # This script is used to remove the specified characters from the filename. # Test the command format if [ -z "$3" -o $1 -gt $2 ];then echo "--Usage: `basename $0` number1 number2 filename filename ..." echo " number1: is the position of the first character to be cut" echo " number2: is the position of the last character to be cut, not less that number1" echo " filename: you can specify more than one files or use wild card" exit 65 fi # Allow more than one files to be specified once while [ -n "$3" ];do if [ ! -e "$3" ];then echo "--Error: The file $3 does not exist" else oldname=`basename $3` echo $oldname > /tmp/file4rename newname=`colrm $1 $2 < /tmp/file4rename` if [ -n "$newname" ];then mv $3 `dirname $3`/$newname echo "--Info: The file $oldname has been renamed to $newname" else echo "--Error: You cannot do that" fi fi shift done # Remove the temporary file rm -f /tmp/file4rename exit 0