#!/bin/bash
#                 /usr/local/bin/clone
# http://crystalfaeries.net/posix/bin/clone
# celeste:crystalfaery 2014-05-05 15:25:30+00:00
# clone is a helper for rsync commands, to clone a set of directories (or files if we extend code)
# from me, to my twin... anticipated usage in scripts is like:
# clone path
# yes, misuse can be dangerous, and yes the inputs aren't sanitized yet

if [[ $# -gt 0 ]]
	then
		if [ "$1" == "--dry-run" ]
			then
				dry_run="$1"
				shift		# we have consumed the argument
			else
				dry_run=""	# go for it
		fi
fi

result=0			# dress for success
while [[ $# -gt 0 ]] ; do	# iterate for each argument
	ssh `my_twin`  mkdir -p "$1"
	rsync -auvzH $dry_run	"$1"/{.??,}*		`/usr/local/bin/my_twin`:"$1"
	result=$?
	shift			# we have consumed the argument
done
exit	$result			# last argument wins, uh oh, is that good?


syntax highlighted by Code2HTML, v. 0.9.1