#!/bin/sh -eux # When invoked with an absolute path name as an argument, redo-whichdo # must output non-existent dofiles in the same directory until it # outputs one that exists. dofiles="default.do default.c.do default.b.c.do a.b.c.do" for dofile in ${dofiles}; do if test -e "${dofile}"; then rm -- "${dofile}" fi done for dofile in ${dofiles}; do >"${dofile}" cat <&2 printf 'redo-whichdo prints %s as nonexistent dofile, but it exists.\n' \ "${whichdo_dofile_nonexistent}" exit 1 fi done whichdo_dofile_existent=$( printf '%s\n' "${whichdo_dofiles}" \ |tail -n1 ) if ! test -e "${whichdo_dofile_existent}"; then >&2 printf 'redo-whichdo prints %s as existent dofile, but it does not exist.\n' \ "${whichdo_dofile_existent}" exit 1 fi done