#!/bin/bash # # Syntax: revdate [-h] script [...] # # Purpose: Returns the revision dates of the given scripts. # The -h flag shows the help info for this command. # Created: Aug 7, 2007 by Bart De Schutter # Last revised: Aug 9, 2007 by Bart De Schutter # # See http://www.deschutter.info/util/scripts.html for the latest version of # this script. # Status: public # Category: files # # Process input arguments. # if [ $# -ge 1 -a "$1" = "-h" ]; then sed '/^$/q;/^#!/d;s/^# //;s/^#//' $0 >&2 exit 1 fi path=${0%/*} echo $path for fil in "$@" do orig_fil=$fil if [ ! -f "$fil" ] then fil="$path/$fil" if [ ! -f "$fil" ] then echo >&2 echo >&2 "ERROR: File $orig_fil not found." echo >&2 exit 1 fi fi date=$(grep '^#[ \t]*Last revised:' "$fil" | sed 's/^#[ \t]*Last revised:[ \t]*//;s/[ \t]*by.*//') if [ -z "$date" ] then date=$(grep '^#[ \t]*Created:' "$fil" | sed 's/^#[ \t]*Created:[ \t]*//;s/[ \t]*by.*//') if [ -z "$date" ] then revdate="Unknown" fi fi year=${date##*,[ \t]} prefix=${date%,*} day=${prefix##*[ \t]} if [ $day -lt 10 ] then day="0$day" fi month=${prefix%%[ \t]*} month=$(echo $month | sed 's/Jan/01/;s/Feb/02/;s/Mar/03/;s/Apr/04/;s/May/05/;s/Jun/06/;s/Jul/07/;s/Aug/08/;s/Sep/09/;s/Oct/10/;s/Nov/11/;s/Dec/12/;') revdate="${year}-${month}-${day}" if [ $# -eq 1 ] then echo $revdate else echo $orig_fil: $revdate fi done