#!/bin/sh set -eu usage() { cat <<-'EOF' Usage: dynmake.sh -n VARNAME -d DIR dynmake.sh -h EOF } help() { cat <<-'EOF' Options: -h, --help show this message EOF } for flag in "$@"; do case "$flag" in --) break ;; --help) usage help exit ;; *) ;; esac done while getopts 'd:n:h' flag; do case "$flag" in d) DIR="$OPTARG" ;; n) NAME="$OPTARG" ;; h) usage help exit ;; *) usage >&2 exit 2 ;; esac done shift $((OPTIND - 1)) assert_arg() { if [ -z "$1" ]; then printf 'Missing %s.' "$2" >&2 exit 2 fi } assert_arg "${DIR:-}" '-d DIR' assert_arg "${NAME:-}" '-n NAME' printf '%s = \\\n' "$NAME" find "$DIR" -type f | sed -e 's/^/ /' \ -e 's/$/ \\/' printf '\n'