Are there semantic rules in shell scripts covering whether multiple usages of "date" return consistent values (as there are for date/time functions within a single REXX statement)? If not, any script with multiple "date" commands like the "long" example given will potentially fail if the midnight boundary is crossed during execution as the Y, m, and d values returned may increment from one invocation to the next and not all of the values examined are guaranteed to be consistent with a single date. For example, if consistency is not guaranteed, the test for day "01" may run while the date is last day of month, and subsequent code which presumes "not day 01" may run after the date has actually changed to day "01".

The example also demonstrates why one really needs some simple command option to do date offsets, as there is no way one can be certain code of this complexity has no syntactic errors just by a visual inspection, and I suspect shell script execution wouldn't necessarily warn of all errors in parts of the statement that are not actually executed during a particular invocation.
    JC Ewing

On 03/14/2013 03:16 PM, Rafal Hanzel ZETO Katowice wrote:
Yes, You're right.

In this situation you need pretty simple script or something like this: long "single command" tested on my linux

if [ `date +%d` -ne 01 ]; then echo "`date +%Y%m%d` - 1" | bc; elif [ `date +%m` -ne 01 ]; then echo $(echo $(date +%Y) $(echo $(date +%m) ) $(cal $(echo "$(date +%m) -1" | bc) $(date +%Y) | tr -d '\n' | tr -d ' ' | tail -c 2) | tr -d ' ') - 100 | bc; else echo $(echo $(date +%Y) 12 $(cal 12 $(echo "$(date +%Y) -1" |bc ) | tr -d '\n' | tr -d ' ' | tail -c 2) | tr -d ' ') - 10000 | bc; fi


I can't try this in USS now, but I hope it works

---
Pozdrawiam/Best regards,

Rafal Hanzel
Programista systemowy, Dział Badań i Rozwoju Systemów Komputerowych
Tel. +48 32 3589246, Fax +48 32 3589277, email: [email protected]
Tel. kom. +48 501677656
Zakład Elektronicznej Techniki Obliczeniowej w Katowicach Spółka z o.o.
40-158 Katowice, ul. Owocowa 1
Sąd Rejonowy Katowice - Wschód w Katowicach Wydział VIII Gospodarczy Krajowego Rejestru Sądowego, KRS 0000051477
Kapitał zakładowy: 264500 zł
NIP 634-013-11-06
http://www.zetokatowice.pl

Jesteśmy uczestnikiem Programu
RZETELNA Firma
Sprawdź naszą rzetelność na
http://www.rzetelnafirma.pl/8FGKEVFH

Treść tej informacji może być poufna, w związku z czym powinna trafić bezpośrednio do rąk adresata. Jakiekolwiek jej ujawnianie, rozpowszechnianie, bądź kopiowanie jest zabronione. W przypadku omyłkowego otrzymania niniejszej informacji prosimy o poinformowanie nadawcy i usunięcie jej z komputera.

W dniu 14.03.2013 14:32, Uwe Oswald napisał(a):
Thx perfect, thats exactly what I need. But I'm afraid this doesn’t
work for the first of a month for example 20130401 will then be
20130400 or I'm wrong?

-----Ursprüngliche Nachricht-----
Von: IBM Mainframe Discussion List [mailto:[email protected]]
Im Auftrag von Rafal Hanzel ZETO Katowice
Gesendet: Donnerstag, 14. März 2013 13:23
An: [email protected]
Betreff: Re: USS "date" command, subtract one day

Maybe something like that, will help you:
echo "`date +%Y%m%d` - 1" | bc

---
Pozdrawiam/Best regards,

Rafal Hanzel


W dniu 14.03.2013 12:54, Uwe Oswald napisał(a):
Hi,

I dont know if this is the right forum but I hope someone could help
anyway. I want to subtract "one day" from the actual date with one USS
unix command.

The actual date I get via "date +%Y%m%d" (for example 20130314), but
"date +%Y%m%d-1" or "...yesterday" don’t work. I have tried everything
without success. Does anybody have a tip for me? It must be achieved
within one command not more.

Thx
Uwe


...

--
Joel C. Ewing,    Bentonville, AR       [email protected] 

----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to [email protected] with the message: INFO IBM-MAIN

Reply via email to