Here's a simple, yet useful script that returns yesterday's date (with all the calendar calculations done properly) on standard output:
#!/usr/bin/perl
use POSIX qw(strftime);
my $yest=time - 60 * 60 * 24;
my $ndst = (localtime $now)[8] > 0;
my $tdst = (localtime $then)[8] > 0;
$yest -= ($tdst - $ndst) * 60 * 60;
print strftime("%F", gmtime($yest))."\n";
I've named it yesterday.pl.
It comes in handy quite often, e.g. when I need to make a directory with yesterday's date in its name:
mkdir $(yesterday.pl)_i_went_mushroom_picking
or make a backup of yesterday's configuration file that I'm going to modify today:
cp config_file.conf config_file_$(yesterday.pl).conf
Oto prosty, lecz dość przydatny skrypt zwracający na standardowym wyjściu wczorajszą datę zgodnie z wszelkimi regułami kalendarza:
#!/usr/bin/perl
use POSIX qw(strftime);
my $yest=time - 60 * 60 * 24;
my $ndst = (localtime $now)[8] > 0;
my $tdst = (localtime $then)[8] > 0;
$yest -= ($tdst - $ndst) * 60 * 60;
print strftime("%F", gmtime($yest))."\n";
Nazwałem go yesterday.pl.
Często się przydaje, na przykład aby założyć katalog o nazwie daty wczorajszej:
mkdir $(yesterday.pl)_wczoraj_bylem_na_grzybach
Albo zrobić kopię zapasową wczorajszej wersji pliku, który będę zmieniał dziś:
cp plik_konfiguracyjny.conf plik_konfiguracyjny_$(yesterday.pl).conf