SUS / POSIX-wrapped "-nt" test compatibility

I am working on porting a bash script to SUS / POSIX compatible shells. I've managed to remove most of the basisms, but I'm currently stuck with the last one.

The script is for creating a crontab based on files in the cron.d directory, and it uses the -nt test to check if any input file has changed since the crontab was created.

Can anyone suggest a good, SUS compliant replacement for the '-nt' check using only the shell utilities mentioned in this specification?

+2


source to share


1 answer


It might actually be simpler than your current solution:

if find $DIRECTORY_OF_INPUT_FILES -type f -newer $CRONTAB_FILE | grep -q .; then
    $REGENERATE_COMMAND
fi

      



That is, you don't need to iterate over all the input files - find will do it for you.

+6


source







All Articles