On Fri, 15 Mar 2013 09:36:41 -0500, Joel C. Ewing wrote:

>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

No.  But the format string for date(1) may be as complex as desired
so the programmer can in a single command extract the date in a
format suitable for testing and another suitable for display.  Even
as in Rexx multiple calls to DATE() in a single phrase (beware the
distinction between "phrase" and "statement") return consistent
values.

>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
>
He should have used a single call to date(1) and parsed the result.

>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 same hazard exists in Rexx or any language.  Suppose you are logging
transactions in data sets separated by months.  Regardless in which order
you perform the operations, it's possible that a March transaction be recorded
in April's log or an April transaction in March's log.  The best you can do
is to extract the date, strictly, only once per transaction, and use that
date both in the report headers and in selection of the log data set.

>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.
>   
That's what I thought.

>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
>> 
And I hope you're not designing any airliners I fly on.

-- gil

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

Reply via email to