tags:

views:

35

answers:

1

I'm working on porting bash script to SUS/POSIX-compliant shells. I was able to remove most of bashisms myself but I'm currently stuck with last one.

The script is for generating crontab based on files in cron.d directory, and it uses '-nt' test to check whether any of input files has changed since last time the crontab was generated.

Can anyone suggest a nice, SUS-compliant replacement of the '-nt' check using only shell utilities mentioned in that spec?

+3  A: 

Actually, this may be easier 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 loop over all the input files - find will do it for you.

Daniel Martin