#!/bin/bash S3_ENDPOINT="yourdomain.com.s3-website-ap-northeast-1.amazonaws.com" SIDE_DOMAIN="yourdomain.com" function forall { for FILE in `ls ${2}` do local FULL=${2}/${FILE} if [ -f $FULL ]; then $1 $FULL elif [ -d $FULL ]; then forall $1 $FULL fi done } function convert { case "$1" in *\.html) sed -i -e "s/${S3_ENDPOINT}/${SIDE_DOMAIN}/g" $1 ;; *) ;; esac } forall convert /pathToHtmlDirectory