bashdatesunos

How to get last Week's date in bash SunOS


Here is my issue: I have a backup bash script that needs to access a folder with a date in its name for example : backup_01072022 .

I used date=`TZ=GMT+24 date +%d%m%Y` when i needed to access the backup folder of yesterday.

Now I want to access the backup folder of last week :

date=`TZ=GMT+168 date +%d%m%Y` , it doesn't work , it show today's date.

I read that TZ doesn't work for a value above +144.

Is there any other way of manipulating dates in SunOS 6.8 ?

Notes :

SunOS 6.8

version of the date util : 8.5

version of bash : 4.1.11(2)-release


Solution

  • Thanks to the helpful commments and answers I was able to make it work using :

    /usr/gnu/bin/date -d "last week" '+%d%m%Y'
    

    It turns out I was not using the GNU date util until I specified it explicitly, and that's neither --date nor -d was working for me. I still can't figure out what date util I was using by default if not GNU date.