LDP/LDP/guide/docbook/abs-guide/rfe.sh

30 lines
611 B
Bash
Raw Normal View History

2001-07-10 14:25:50 +00:00
#!/bin/bash
2005-05-08 20:09:31 +00:00
# rfe.sh: Renaming file extensions.
2001-07-10 14:25:50 +00:00
#
# rfe old_extension new_extension
#
# Example:
# To rename all *.gif files in working directory to *.jpg,
# rfe gif jpg
2005-05-08 20:09:31 +00:00
2001-07-10 14:25:50 +00:00
E_BADARGS=65
2005-05-08 20:09:31 +00:00
case $# in
0|1) # The vertical bar means "or" in this context.
2001-07-10 14:25:50 +00:00
echo "Usage: `basename $0` old_file_suffix new_file_suffix"
2005-05-08 20:09:31 +00:00
exit $E_BADARGS # If 0 or 1 arg, then bail out.
;;
esac
2001-07-10 14:25:50 +00:00
for filename in *.$1
# Traverse list of files ending with 1st argument.
do
mv $filename ${filename%$1}$2
2002-04-01 16:04:17 +00:00
# Strip off part of filename matching 1st argument,
#+ then append 2nd argument.
2001-07-10 14:25:50 +00:00
done
exit 0