Re: days-between

From: Ted Breen (ted_breen_at_team.telstra.com)
Date: 01/07/04


Date: Wed, 7 Jan 2004 17:21:34 +1100


Chris F.A. Johnson wrote in message ...
>On Wed, 07 Jan 2004 at 03:21 GMT, Ted Breen wrote:
>>
>> Chris,
>> I put the two changes to date1 and date2 and the original script now
>> seems OK.
>> I am having some trouble running the new script with #!/bin/sh.
>> I get a list of files interspersed with the maths.
>
> The list of files is probably because a variable is not quoted;
> the quick solution is to add "set -f" at the beginning of the
> sript.

With "set -f" I get
days_between.cfj 07/01/2004 19/01/2004
$(( $(( ( 1461 * ( 2004 + 4800 + ( 01 - 14 ) / 12 ) ) / 4 + ( 367 * ( 01 -
2 - 12 * ( ( 01 - 14 ) / 12 ) ) ) / 12 - ( 3 * ( ( 2004 + 4900 + ( 01 - 14 )
/ 12 ) / 100 ) ) / 4 + 19 - 32075 )) - $(( ( 1461 * ( 2004 + 4800 + ( 01 -
14 ) / 12 ) ) / 4 + ( 367 * ( 01 - 2 - 12 * ( ( 01 - 14 ) / 12 ) ) ) / 12 -
( 3 * ( ( 2004 + 4900 + ( 01 - 14 ) / 12 ) / 100 ) ) / 4 + 07 - 32075 )) ))
>
> Are you sure that's a Korn shell?

No. Only that the man sh says that it is.
The software has not been updated for many years.

>
> If it's not, you should get a syntax error (Bourne shell):
>
>$ echo $(( 3 + 4 ))
>syntax error: `(' unexpected
> Try a simple addition:
>
>echo $(( 4 + 4 ))
> Or even:
>eval echo $(( 4 + 4 ))

The default shell is csh
I put #!/bin/sh at the start of the script. and also tried #!/sbin/sh.

4% echo $(( 3 + 4 ))
Variable syntax

5% sh
$ echo $(( 3 + 4 ))
$(( 3 + 4 ))
$ eval echo $(( 4 + 4 ))
$(( 4 + 4 ))
$ ^D

6% eval echo $(( 4 + 4 ))
Variable syntax
7% which sh
/sbin/sh
8% ls -la /sbin/sh
-rwxr-xr-x 1 root sys 390564 Jan 28 1999 /sbin/sh
9% which ksh
/sbin/ksh
10% ls -la /sbin/ksh
lrwxr-xr-x 1 root sys 2 Jan 28 1999 /sbin/ksh -> sh

It's great to see that the original script has been updated but it probably
should have the date
in the comment so that this discussion makes sense.

>
> Chris F.A. Johnson http://cfaj.freeshell.org
> ===================================================================
> My code (if any) in this post is copyright 2004, Chris F.A. Johnson
> and may be copied under the terms of the GNU General Public License



Relevant Pages

  • Re: alphabetizing in BASIC
    ... >>(In original Beginners All-purpose Symbolic Instruction Code there ... >>any string variables originally, and you only had 26 variables in ... > Syntax Error in Line 6 - you must be a Natural Scientist. ... > You remember, Chris? ...
    (comp.programming)
  • Re: function in .bashrc problem
    ... bashrc, or any permissions to read/source them? ... Closing the shell in opensuse and ... syntax error even after it was fixed. ... Shared Hosting, Reseller Hosting, Dedicated & Semi-Dedicated servers ...
    (comp.os.linux.misc)
  • Re: understanding NOT IN / IN
    ... Mark D Powell wrote: ... Chris, I can duplicate your results on 9.2.0.6 and 10.2.0.3 but I do ... I see no reason for a syntax error. ...
    (comp.databases.oracle.server)
  • RE: Syntax error when using right function
    ... Please post the SQL of your query ... "Chris E." ... But I cannot seem to find a solution for the syntax error. ...
    (microsoft.public.access.queries)
  • Re: Issue with bc and echo in script
    ... % echo /| bc ... What shell are you using? ... syntax error near unexpected token `3*4' ... My message was confusing, sorry. ...
    (comp.unix.shell)