cancel
Showing results for 
Search instead for 
Did you mean: 

Date Calculation Failed

SOLVED
Go to solution
David Yandry
Frequent Advisor

Date Calculation Failed

Hi gurus,

I have used caljd.sh many times with no problems but today when I tried to use it, it produced this error.

$ caljd.sh -S "-" -o -e 2454250
./caljd.sh: line 129: typeset: -Z: invalid option
typeset: usage: typeset [-afFirtx] [-p] name[=value] ...
./caljd.sh: line 131: typeset: -Z: invalid option
typeset: usage: typeset [-afFirtx] [-p] name[=value] ...
./caljd.sh: line 137: typeset: -Z: invalid option
typeset: usage: typeset [-afFirtx] [-p] name[=value] ...
awk: cmd. line:3: while ((knt < 4) && "locale LC_TIME 2>/dev/null" | \c
awk: cmd. line:3: ^ backslash not last character on line
00--0000


I also tried it with a newer version and get the same error.

Any ideas?

Thanks,
David
11 REPLIES
James R. Ferguson
Acclaimed Contributor

Re: Date Calculation Failed

Hi David:

Perhaps you fetched a new version from the ITRC; saved in on a Windows platform and FTP'd it in binary mode to a Unix server. In that case, you have linefeed+carriage-return characters instead of simple linefeeds as your line delimiters.

If you do 'cat -etv file' you will see:

^M$

at the line's termination.

If this is the case, eliminate the carriage returns with:

# dos2ux caljd.sh > caljd.sh.new
# mv caljd.sh.new caljd.sh

Regards!

...JRF...
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: Date Calculation Failed

OK David. Fess up. What shell are you trying to run caljd.sh under? This may be yet another opportunity for me to bash bash.

Try using caljd.pl instead. I'll bet that it works.
If it ain't broke, I can fix that.
David Yandry
Frequent Advisor

Re: Date Calculation Failed

Hi JRF:

Thanks for replying but I was careful to download the script.

Hi ACS:
I am trying to run under bash but that was after it did not work under ksh. I got this output when I tried the same values under ksh.

$ caljd.sh -S "-" -o -e 2454250
00--0000

I will try the perl version but I would really like to fix the shell version.

Thanks,
David
A. Clay Stephenson
Acclaimed Contributor

Re: Date Calculation Failed

OK David. Fess up some more. This ain't HP-UX is it? My psychic, Miss Cleo, tells me that you are one of them Linux fellers. Why ain't you posting this in Linux where it belongs?

In any event, caljd.pl will work in Linux (or Windows for that matter) and that is what I consider to be the portable caljd.xx version.

Most bash implementations fail with this construct:

echo "Stupid Bash" | read A B
echo "A = \"${A}\""
echo "B = \"${B}\""

${B} will be NULL rather than "Bash". You bash boys can argue about lvalues and subprocesses but this is a handy feature for parsing data.

Bash also does not know about "Z" (Zero-padded) variables.

If it ain't broke, I can fix that.
David Yandry
Frequent Advisor

Re: Date Calculation Failed

Hi ACS:

Yes, I am running redhat linux :(. Is there any way to fix caljd.sh to work on Linux?

Thanks,
David
James R. Ferguson
Acclaimed Contributor

Re: Date Calculation Failed

Hi (again) David:

Well, you now have learned that a shell comes in many flavors and a script written for one insn't necessary portable to under without some work.

As Clay noted, use his Perl version. That will work without any effort on your part!

Regards!

...JRF...
James R. Ferguson
Acclaimed Contributor

Re: Date Calculation Failed

Hi (again):

To add: In fact, I submit that Clay should STOP parallel enhancements to caljd.sh and caljd.pl and only provide NEW features in caljd.pl [ assuming that anything is left of the alphabet :-) ]. In that fashion, this my-shell-ain't-your-shell nonsense would cease!

Regards!

...JRF...
A. Clay Stephenson
Acclaimed Contributor

Re: Date Calculation Failed

Well David, Jim has given me something to think about.

I will say that under Linux zsh is the least evil shell that I have found. Caljd.sh should work under zsh with one change: there is a line inside the AWK() function, "readonly AWKEXE". Comment out that line and zsh should work. Linux has a number of other 'improvements' such as the echo command. By default, echo "Test \c" outputs "Test \c" whereas in real UNIX, echo "Test \c" outputs "Test ". It would be easy enough to replace -Z variables with a function that pads data and I could probably add something that puts echo in a compatible mode and conditionally handle the
echo "Stupid Bash" | read A B problem ("feature" if you are a bash guy) but Perl sounds like a whole lot easier answer.

After all, you don't have to know anything about Perl to use caljd.pl, just replace ".sh" in your scripts which call caljd.sh with ".pl" and declare victory.

One thing I will say with absolute confidence is that no version of caljd.sh that I write will ever run under csh.

If it ain't broke, I can fix that.
A. Clay Stephenson
Acclaimed Contributor

Re: Date Calculation Failed

OK David. Here is caljd.sh, Vrsn 2.3 s. Other than bug fixes, (which henceforth will not include "this doesn't work under my shell"), any newer features will be found only in the Perl version of the script.

In any event, if a stupid shell is detected which does not correctly (and I get to define 'correctly') handle
echo "Stupid Bash" | read A B
then I execute
echo "Stupid Bash" > tempfile
read A B < tempfile
instead.

Similarly, if a stupid shell is detected which does not execute
echo "Stupid Bash\c"
correctly, I assert a shell option which changes the behavior of echo.

I also removed all references to "typeset -Z" because not all shells support -Z (zero-padded) variables. Instead, I call a function to do the padding.

I had already addressed a problem under Solaris. For some reason, Sun missed the memo about 20 years ago that nawk (new awk) could be renamed or linked to awk. For anyone wanting to use the original awk, oawk (old awk) is still available. In any event, if nawk is in the PATH, it will be used otherwise awk will be used.
If it ain't broke, I can fix that.
David Yandry
Frequent Advisor

Re: Date Calculation Failed

Hi ACS,

The new version works great on Linux. I tried it under bash and ksh and it worked like a champ!

Thanks,
David



A. Clay Stephenson
Acclaimed Contributor

Re: Date Calculation Failed

Fine, David. You don't know how relieved I am to know that caljd.sh works under bash.

I suppose I should add that I did add a few comments about how the "shbang" line should be set so that the only change needed for various platforms should be changing the shbang line BUT I consider caljd.pl to be the much more portable answer because the ONLY change that might be needed is a symbolic link from wherever Perl really is to /usr/bin/perl.



If it ain't broke, I can fix that.