[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

OT: Output from date command - my little backup script



Is the output from the date command a string or integer wrt date +%w?

I'm trying to test a condition in my backup script where i want to
match on day of week = 0

The program flow I am trying to achieve is" If the file exists and the
day of the week is 0 then remove the file and set the day of the week
to 0, otherwise set the day of the week to 0(perform Level 0 backup)".

>From man test i have 2 possibilities that i'm aware of, $backuplevel
-eq 0 and $backuplevel = 0

if [ -f "$incrementalfile" ]
  then
    backuplevel=`date +%w`
    if [ $backuplevel -eq 0]
      then
        rm "$incrementalfile" > /dev/null 2>&1
    fi
  else
    backuplevel=0
fi

I have also tried if [ $backuplevel = 0 ]

But neither seems to match, that is to say that the incremental file
does not get deleted so it continues to do an 'other than 0 level
backup.
The command echo $backuplevel returns 0 but I don't know if it is an
integer or a string, or is it both?
According to [1] Bash variables are untyped but I don't know why
neither of them match and delete my file.
Severely confused,

Adrian

[1] http://tldp.org/LDP/abs/html/untyped.html
-- 
24x7x365 != 24x7x52 Stupid or bad maths?
<erno> hm. I've lost a machine.. literally _lost_. it responds to
ping, it works completely, I just can't figure out where in my
apartment it is.


Reply to: