#!/bin/bash -eu if [[ $# == 0 || ! -d $1 ]]; then echo >&2 "Usage: $0 include_dir file_to_replace..." exit 1 fi include_dir="$1" shift HEADER="${include_dir}/head.html" NAV_BAR="${include_dir}/nav.html" FOOTER="${include_dir}/footer.html" for f in "${include_dir}"/{head,nav,footer}.html; do if [[ ! -e "${f}" ]]; then echo >&2 "Need ${f} to exist" exit 1 fi done perl -MFile::Slurp -pi -e 'BEGIN { $header = read_file("'$HEADER'") } s##$header #' "$@" perl -MFile::Slurp -pi -e 'BEGIN { $nav = read_file("'$NAV_BAR'") } s##
$nav
#' "$@" perl -MFile::Slurp -pi -e 'BEGIN { $footer = read_file("'$FOOTER'") } s##
$footer
#' "$@"