script on strike?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting script on strike?
# 1  
Old 12-24-2005
script on strike?

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
# 2  
Old 12-24-2005
The script did not give me that error. It seemed to run fine.
# 3  
Old 12-24-2005
Ruby:

Code:
# convert, for example, 2005321 to 20051117

require 'date'

# If no command-line argument, read STDIN.
date = ARGV.first || gets.chomp!

puts Date.new2( date[0,4].to_i, date[-3,3].to_i ).to_s.gsub(/-/,"")

# 4  
Old 12-27-2005
dear Perderabo

It's nice to know that some place the script can do what is expected:
Quote:
Originally Posted by Perderabo
The script did not give me that error. It seemed to run fine.
However, I'd like to know what it wants to run in this here box of mine.
By the by, what's your PC's case color?

yours`
serguey
# 5  
Old 12-27-2005
dear futurelet,

please do not drive me so fast.
Where in the original script should I insert your generous line?
(I'm not so agile with sh-shell-scripting and need some more instructive clues.)

yours`
serguey
# 6  
Old 12-27-2005
hmm
how about replacing the line

while [ `expr $d \> 0` = 1 ]

by
while [ `expr $d \> 0` -eq 1 ]
# 7  
Old 12-28-2005
dear linuxpenguin

I swapped the unexpected "=" for -eq.
Please, peruse:
Script started on Wed Dec 28 11:19:31 2005
# sh -v yd2ymd 1998321
if [ X$1 = X ]
then
read dt

else
dt=$1

fi


y=`expr $dt / 1000`

d=`expr $dt % 1000`

m=1

while [ `expr $d \> 0` -eq 1 ]

do
md=`sh monthdays $y $m`
d=`expr $d \- $md`
m=`expr $m \+ 1`

done
expr: illegal option -- 1
usage: expr [-e] expression
[: -eq: unexpected operator

d=`expr $d \+ $md`
expr: illegal option -- 1
usage: expr [-e] expression

m=`expr $m \- 1`

grg=`expr \( $y \* 10000 \) \+ \( $m \* 100 \) \+ $d`
expr: syntax error
echo $grg
===============================
yours`
serguey
Login or Register to Ask a Question

Previous Thread | Next Thread

6 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script works fine as a standalone script but not as part of a bigger script

Hello all, I am facing a weird issue while executing a code below - #!/bin/bash cd /wload/baot/home/baotasa0/sandboxes_finance/ext_ukba_bde/pset sh UKBA_publish.sh UKBA 28082015 3 if then echo "Param file conversion for all the areas are completed, please check in your home directory"... (2 Replies)
Discussion started by: ektubbe
2 Replies

2. UNIX for Dummies Questions & Answers

Calling a script from master script to get value from called script

I am trying to call a script(callingscript.sh) from a master script(masterscript.sh) to get string type value from calling script to master script. I have used scripts mentioned below. #masterscript.sh ./callingscript.sh echo $fileExist #callingscript.sh echo "The script is called"... (2 Replies)
Discussion started by: Raj Roy
2 Replies

3. Shell Programming and Scripting

Script will keep checking running status of another script and also restart called script at night

I am using blow script :-- #!/bin/bash FIND=$(ps -elf | grep "snmp_trap.sh" | grep -v grep) #check snmp_trap.sh is running or not if then # echo "process found" exit 0; else echo "process not found" exec /home/Ketan_r /snmp_trap.sh 2>&1 & disown -h ... (1 Reply)
Discussion started by: ketanraut
1 Replies

4. Shell Programming and Scripting

strike last part from list of files

Hi, I have list of files as following: /home/abc/x/23344.php /home/axx/zz/ddddd/abc/7asda/2434.php /home/zzz/7x/y/114.php /home/assssc/x/yasyday/23664.php ( last part in each line is <somenumber.php> I need to somehow get this from the above: /home/abc/x/... (6 Replies)
Discussion started by: fed.linuxgossip
6 Replies

5. SuSE

Lord of the Rings and Counter Strike on OpenSUSE 11.1

is it possible to get Lord of the Rings Battle for Middle Earth 2 and Counter Strike working on OpenSUSE 11.1? i'm dual booting SUSE with XP but if i can get those games working then there is no need for Windows. Thanks (1 Reply)
Discussion started by: brendanb
1 Replies

6. Shell Programming and Scripting

create a shell script that calls another script and and an awk script

Hi guys I have a shell script that executes sql statemets and sends the output to a file.the script takes in parameters executes sql and sends the result to an output file. #!/bin/sh echo " $2 $3 $4 $5 $6 $7 isql -w400 -U$2 -S$5 -P$3 << xxx use $4 go print"**Changes to the table... (0 Replies)
Discussion started by: magikminox
0 Replies
Login or Register to Ask a Question