home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.unix.shell
- Path: sparky!uunet!charon.amdahl.com!amdahl!rtech!sgiblab!darwin.sura.net!paladin.american.edu!howland.reston.ans.net!spool.mu.edu!uwm.edu!caen!saimiri.primate.wisc.edu!relay!starfleet.nswc.navy.mil!rweisbe
- From: rweisbe@starfleet.nswc.navy.mil (Bob Weisbeck)
- Subject: for loop termination
- Message-ID: <1993Jan27.190516.29466@relay.nswc.navy.mil>
- Sender: news@relay.nswc.navy.mil
- Organization: Naval Surface Warfare Center
- Date: Wed, 27 Jan 1993 19:05:16 GMT
- Lines: 79
-
-
- I'm not sure why this happens but here goes. I have a script that
- I'm executing but it does not terminate the loop properly and I'm
- not sure what is wrong with it. The script is as follows:
-
-
- #!/bin/sh
- #FILES=`cut -f1 -d" " < datafile`
- FILES=`cat datafile`
- set $FILES
- rm -f manf
- echo "number of params=$#"
- echo "initial arguments =$*==="
- for file in $*
- do
- echo "loop top"
- SUM=`sum -r $1 | tr -s " " | cut -f1-2 -d" "`
- WC=`wc -l $1 | tr -s " " | cut -f2 -d" "`
- LS=`ls -is $1 | tr -s " " | cut -f2-3 -d" "`
- echo "$SUM $WC $LS $1 $2" >> manf
- # shift
- shift 2
- echo "arguments left =$*======"
- echo "number of parameters=$#\n"
- done
- echo "end script"
-
-
- The file has the following in it:
-
- starfleet$cat datafile
- /tmp/file1 lady
- /tmp/file2 tramp
- /tmp/hh jock
- /tmp/xx trusty
-
-
- When I execute it I get the following:
-
- starfleet$scrip2
- number of params=8
- initial arguments =/tmp/file1 lady /tmp/file2 tramp /tmp/hh jock /tmp/xx trusty===
- loop top
- arguments left =/tmp/file2 tramp /tmp/hh jock /tmp/xx trusty======
- number of parameters=6
-
- loop top
- arguments left =/tmp/hh jock /tmp/xx trusty======
- number of parameters=4
-
- loop top
- arguments left =/tmp/xx trusty======
- number of parameters=2
-
- loop top
- arguments left =======
- number of parameters=0
-
- loop top
-
- ((((((( here I have to cntl c out of the script )))))
-
-
-
- The file manf is ok and all the individual commands execute
- as expected.
- Why is the loop not terminating? If I change the script and
- cut out the second field in the datafile file and then shift only
- once after each pass in the loop, it works great (NOTE THE
- COMMENT LINES IN THE SCRIPT).
-
- I figure that there is something obvious that I'm not seeing
- right now. And as soon as I decide to post this I'll see it
- (I hope :^) ).
-
-
- Thanks in advance.
-
- Bob
-