![]() # alternatively (and this is system-dependent) A clarification by OP mentioned the platform, so one could use stat as an alternative to temporary files (compare OSX and Linux): #!/bin/bash use the -nt operator in test to make the comparison you asked for.create another temporary file with the date you want to compare against.They were not carried forward into the test utility when the conditional command was removed from the shell because they have not been included in the test utility built into historical implementations of the sh utility. Some additional primaries newly invented or from the KornShell appeared in an early proposal as part of the conditional command ( ]): s1 > s2, s1 < s2, str = pattern, str != pattern, f1 -nt f2, f1 -ot f2, and f1 -ef f2. POSIX comments about this in the rationale for test: The test program used in Linux (part of coreutils) has extensions for timestamp comparison ( -nt and -ot) not found in POSIX test. use the touch command (adding 0s for hour/minute/second) to set the modification date for the temporary fileīecause your question is about bash, you likely are using Linux. ![]() extract the year/month/day values into a shell variable,.Here's a version that is untested but should work on Macs (and on FreeBSD etc) if I've read the on-line man pages correctly: #! /bin/bashįdate=$(basename "$f". & echo "$f has been modified after $fdate" # get modified timestamp of file in secs since epoch # convert it to seconds since epoch + 1 dayįsecs=$(echo $(date +%s -d "$fdate") + 86400 | bc ) It requires GNU versions of sed, date, and stat $ cat check-dates.shįdate=$(basename "$f". The following script will check the dates of all files specified on the command line:
0 Comments
Leave a Reply. |