#!/bin/bash
#                      /usr/local/bin/re_name
# http://crystalfaeries.net/posix/bin/re_name
# celeste:crystalfaery 2015-10-13 00:42:29+00:00
# http://www.linux-mag.com/id/7171/2/

while read -r oldfile
do
	printf -v prefix '%03d' $((i++))
	case "$oldfile" in
	*[\'\"]*)
		# Make mv -i "$oldfile" "${prefix}_$oldfile"
		echo -E "$oldfile" | sed \
		-e 's/\\/&&/g' \
		-e 's/"/\\"/g' \
		-e 's/.*/"&"/' \
		-e h \
		-e "s/^\"/\"${prefix}_/" \
		-e x -e G -e 's/\n/ /' \
		-e 's/^/mv -i /'
	;;
	*)
		# Output single-quoted arguments:
		echo "mv -i '$oldfile' '${prefix}_$oldfile'"
	;;
	esac
done


syntax highlighted by Code2HTML, v. 0.9.1