home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / unix / shell / 5515 < prev    next >
Encoding:
Text File  |  1993-01-28  |  2.3 KB  |  90 lines

  1. Newsgroups: comp.unix.shell
  2. 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
  3. From: rweisbe@starfleet.nswc.navy.mil (Bob Weisbeck)
  4. Subject: for loop termination
  5. Message-ID: <1993Jan27.190516.29466@relay.nswc.navy.mil>
  6. Sender: news@relay.nswc.navy.mil
  7. Organization: Naval Surface Warfare Center
  8. Date: Wed, 27 Jan 1993 19:05:16 GMT
  9. Lines: 79
  10.  
  11.  
  12.    I'm not sure why this happens but here goes.  I have a script that 
  13.    I'm executing but it does not terminate the loop properly and I'm
  14.    not sure what is wrong with it. The script is as follows:
  15.  
  16.  
  17. #!/bin/sh
  18. #FILES=`cut -f1 -d" " < datafile`
  19. FILES=`cat datafile`
  20. set $FILES 
  21. rm -f manf 
  22. echo "number of params=$#"
  23. echo "initial arguments =$*==="
  24. for file in $*
  25. do
  26.   echo "loop top"
  27.   SUM=`sum -r $1 | tr -s " " | cut -f1-2 -d" "`
  28.   WC=`wc -l $1  | tr -s " " | cut -f2   -d" "`
  29.   LS=`ls -is $1 | tr -s " " | cut -f2-3 -d" "`
  30.   echo "$SUM $WC $LS $1 $2" >> manf
  31. # shift
  32.   shift 2
  33.   echo "arguments left =$*======"
  34.   echo "number of parameters=$#\n"
  35. done
  36. echo "end script"
  37.  
  38.  
  39.    The file has the following in it:
  40.  
  41. starfleet$cat datafile
  42. /tmp/file1 lady   
  43. /tmp/file2 tramp  
  44. /tmp/hh jock   
  45. /tmp/xx trusty
  46.  
  47.  
  48.    When I execute it I get the following:
  49.  
  50. starfleet$scrip2
  51. number of params=8
  52. initial arguments =/tmp/file1 lady /tmp/file2 tramp /tmp/hh jock /tmp/xx trusty===
  53. loop top
  54. arguments left =/tmp/file2 tramp /tmp/hh jock /tmp/xx trusty======
  55. number of parameters=6
  56.  
  57. loop top
  58. arguments left =/tmp/hh jock /tmp/xx trusty======
  59. number of parameters=4
  60.  
  61. loop top
  62. arguments left =/tmp/xx trusty======
  63. number of parameters=2
  64.  
  65. loop top
  66. arguments left =======
  67. number of parameters=0
  68.  
  69. loop top
  70.  
  71. ((((((( here I have to cntl c out of the script   )))))
  72.  
  73.  
  74.  
  75.   The file manf is ok and all the individual commands execute
  76.   as expected. 
  77.   Why is the loop not terminating?  If I change the script and 
  78.   cut out the second field in the datafile file and then shift only
  79.   once after each pass in the loop, it works great (NOTE THE
  80.   COMMENT LINES IN THE SCRIPT). 
  81.  
  82.   I figure that there is something obvious that I'm not seeing 
  83.   right now. And as soon as I decide to post this I'll see it
  84.   (I hope :^)  ).  
  85.  
  86.  
  87.   Thanks in advance.
  88.  
  89.    Bob
  90.