Cover V05, I10
Article
Listing 1
Listing 2
Listing 3
Listing 4
Listing 5

oct96.tar


Listing 3: setdate

#! /bin/bash -
#  FILENAME: setdate
#  Sets date to current one in html files in English or national style.
#
# Luca Salvadori  1996
#
# Setting global environment variables
. setvar
DEFFILE='*.htm'
DATE="\([0-9][0-9]/[0-9][0-9]/[0-9][0-9][0-9][0-9]\)"
# Parsing input parameters
case $1 in
-h|-H|--help)
# Help routine
echo "Usage: setdate [file [lang]]"
echo "Where file is the file(s) to change date to, lang is
the language to use."
exit;;
"")
echo -n "Enter file (default=*.htm): "
read FILE
FILE=${FILE:-${DEFFILE}}
;;
*)
FILE=$1
;;
esac
case $2 in
"")
echo -n "Enter language (default=$BASE_LANG): "
read LANG
LANG=${LANG:-$BASE_LANG}
;;
*)
LANG=$2
;;
esac
# Defining date format to be used upon selected language
case $LANG in
$BASE_LANG)
NEWDATE=`/bin/date +%d/%m/%Y`
;;
$OTHER_LANG)
NEWDATE=`/bin/date +%m/%d/%Y`
;;
*)
echo "ERROR - Language \"$LANG\" is not supported"
exit 1
;;
esac

# here begins the real stuff
for file in ${FILE}
do
if [ ! -f ${file} ]
then
# Check for errors
echo "ERROR - $file does not exist."
exit 1
fi
# Saving original file, just in case...
mv $file $file.$$
# Changing date
echo -n "Changing date to $file... "
cat $file.$$ | sed \
"s;$DATE;$NEWDATE;" >> $file
# Cleanup befor exit
rm $file.$$
echo "Done."
done
exit