#!/bin/sh process () { local old="$1" local new="${1//$first/$second}" [[ ! -e "$new" ]] && { mv "$old" "$new" || exit 1 } } first="$1" shift second="$1" shift while [[ "$1" != "" ]] ; do process "$1" shift done