Answers:
#!/bin/bash
copy_file_and_dependencies() {
PROGRAM="$1"
DEPENDENCIES="$(ldd "$PROGRAM" | awk '{ print $3 }' | grep -v '(' | grep -v 'not a dynamic executable')"
mkdir -p "${JAIL}$(dirname $PROGRAM)"
cp -Lv "$PROGRAM" "${JAIL}${PROGRAM}"
for f in $DEPENDENCIES; do
mkdir -p "${JAIL}$(dirname $f)"
cp -Lv "$f" "${JAIL}${f}"
done
}
export -f copy_file_and_dependencies
copy_file_and_dependencies /etc/ld.so.cache
copy_file_and_dependencies /bin/sh
# ...