Shell script to copy the referenced file permissions to another file (BSD).
#!/bin/sh
#
# Copies the referenced file's permissions to another file (BSD).
#
# see: http://unix.stackexchange.com/a/20650
#
set -e
reference_file=$1
if [ -z "${reference_file}" ]; then
echo "Usage: cp-permissions <reference_file> <target_file(s)>"
echo " Copies the referenced file's permissions to another file (BSD)."
exit 1
fi
shift
target_files=$*
chmod $(stat -f '%Lp' "${reference_file}") "${target_files}"