dear sages,
please tell me what's wrong with the following script:
#!/bin/sh
#usage yd2ymd 1998213
# if there is no command line argument, assume one is being
# piped in and read it
if [ X$1 = X ]
then
read dt
else
dt=$1
fi
# break apart the year and the days
y=`expr $dt / 1000`
d=`expr $dt % 1000`
# subtract the number of days in each month starting from 1
# from the days in the date. When the day goes below 1, you
# have the current month. Add back the number of days in the
# month to get the correct day of the month
m=1
while [ `expr $d \> 0` = 1 ]
do
md=`sh monthdays $y $m`
d=`expr $d \- $md`
m=`expr $m \+ 1`
done
d=`expr $d \+ $md`
# the loop steps one past the correct month, so back up the month
m=`expr $m \- 1`
# assemble the results into a gregorian date
grg=`expr \( $y \* 10000 \) \+ \( $m \* 100 \) \+ $d`
echo $grg
---------------------
and all that resulted in --
---------------------
yd2ymd: 38: Syntax error: end of file unexpected (expecting "do")
# % >
Note: the script was copied from a tutorial, I only added "sh" in the line--
md=`monthdays $y $m`
to avoid "not found" message; the monthdays file is in its place and working OK.
yours`
serguey
please tell me what's wrong with the following script:
#!/bin/sh
#usage yd2ymd 1998213
# if there is no command line argument, assume one is being
# piped in and read it
if [ X$1 = X ]
then
read dt
else
dt=$1
fi
# break apart the year and the days
y=`expr $dt / 1000`
d=`expr $dt % 1000`
# subtract the number of days in each month starting from 1
# from the days in the date. When the day goes below 1, you
# have the current month. Add back the number of days in the
# month to get the correct day of the month
m=1
while [ `expr $d \> 0` = 1 ]
do
md=`sh monthdays $y $m`
d=`expr $d \- $md`
m=`expr $m \+ 1`
done
d=`expr $d \+ $md`
# the loop steps one past the correct month, so back up the month
m=`expr $m \- 1`
# assemble the results into a gregorian date
grg=`expr \( $y \* 10000 \) \+ \( $m \* 100 \) \+ $d`
echo $grg
---------------------
and all that resulted in --
---------------------
yd2ymd: 38: Syntax error: end of file unexpected (expecting "do")
# % >
Note: the script was copied from a tutorial, I only added "sh" in the line--
md=`monthdays $y $m`
to avoid "not found" message; the monthdays file is in its place and working OK.
yours`
serguey