2 # Copy files in argument-selected subdirectories of $1 to subdirectories
3 # of $2 (which may be an empty string), e.g. with $1 of "etc_files", $2
4 # of "" and $3 of "all", copy files below etc_files/all such as
5 # etc_files/all/etc/foo/bar to equivalent locations below / such as
6 # /etc/foo/bar. Create directories as necessary. Multiple arguments after
9 # CAUTION: This removes original files at the affected paths.
13 expect_n_args 3 "(source root, target root, modules)" "$@"
19 for target_module in "$@"; do
20 mkdir -p "${source_root}/${target_module}"
21 cd "${source_root}/${target_module}"
22 for path in $(find . -type f); do
23 target_path="${target_root}"$(echo "${path}" | cut -c2-)
24 source_path=$(realpath "${path}")
25 dir=$(dirname "${target_path}")
27 cp "${source_path}" "${target_path}"