Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Syntax error at line 6 : `jd=$1' is not expected.

Status
Not open for further replies.

LotoL

Programmer
Mar 17, 2004
20
CA
Having problems create a function to convert julian date to a date format of YYYYMMDD. Not sure If im doing this right.

I getting an error code
./j2g[3]: 0403-057 Syntax error at line 6 : `jd=$1' is not expected.


#!/bin/ksh
+2
+3 function juliandate_to_gregdate{
+4
+5 jd=${1}
+6
+7 typeset -i l= ${jd} + 68569
+8 echo ${l}
+9 typeset -i n=(( 4 * ${l} ) / 146097)
+10 echo ${n}
+11 ${l} = ${l} - (( 146097 * ${n} + 3 ) / 4)
+12 echo ${l}
+13 typeset -i i=(( 4000 * ( ${l} + 1 ) ) / 1461001)
+14 echo ${i}
+15 ${l} = ${l} - ((( 1461 * ${i} ) / 4) + 31)
+16 echo ${l}
+17 typeset -i j=( 80 * ${l} ) / 2447
+18 echo ${j}
+19 typest -i d=${l} - (( 2447 * ${j} ) / 80)
+20 echo ${d}
+21 ${l} = (${j} / 11)
+22 echo ${l}
+23 typeset -i m=${j} + 2 - ( 12 * ${l} )
+24 echo ${m}
+25 typeset -i y=100 * ( ${n} - 49 ) + ${i} + ${l}
+26 echo ${y}
+27 typeset -i gregdate=${ y}${m}${d}
+28 echo $gredate
+29 }
 
Hi,

Just a classical syntax problem.
Keep in mind that shell is not a complier but interpreter and it needs space or tab as delimieters for its tokens.

this will work : function juliandate_to_gregdate {
# a space before lect brace.

take care, you have some confusion in writing numeric expressions

#this instruction ( and all kind of ) will fail too
typeset -i l= ${jd} + 68569
# use this : no spaces before or after =
typeset -i l=${jd} + 68569
# you must write :
typeset -i l=0
(( l = jd + 68569 ))

# numeric expressions must be evaluated like this :

X=0 # init X variable
(( X = ( X + 123) / 12 )) # compute X

# (( 2 left parentheses then expression then 2 right parentheses ))
# expression can contains its own parentheses
# variables whithin (( and )) can be used without $ dollar sign


if you want to assign a computed expression to a var :

somuser@somehost:/tmp:Y=$(( 2 * 20 + (45 - 6 ) / 7 ))
somuser@somehost:/tmp:echo $Y
45


Ali



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top