# # This script adds or removes the specified extension to all files in the # specified directory. if [ $# -lt 2 ]; then echo "Options: -a -r -d" >&2 echo "Please provide a file extension to add or remove" echo "You may also provide a directory. If none is provided, the current" echo "directory will be used." exit 1 fi dch { if [ -d "$1" ]; then cd "$1" cur=0 elseif [ "$1" = -d ]; then incl=y fi } cur=1 while [ -n "$1" ]; do dch "$1" if [ "$1" = -a ]; then dch "$3" dch "$4" for c in '*'; do if ! [ "$c" = change -a "$cur" = 1 ]; then if [ -d "$c" -a "$incl" != y ]; then continue fi mv "$c" "$c.$2" ((f=f+1)) fi done elseif [ "$1" = -r ]; then dch "$3" dch "$4" for c in *; do if ! [ "$c" = change -a "$cur" = 1 ]; then if [ -d "$c" -a "$incl" != y ]; then continue fi mv "$c" "${c%.$2}" 2> /dev/null ((f=f+1)) fi done fi shift done echo "$f files changed." exit 0