home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / unix / shell / 3953 < prev    next >
Encoding:
Internet Message Format  |  1992-09-14  |  1.4 KB

  1. Path: sparky!uunet!mcsun!sunic!psinntp!psinntp!ncrlnk!usglnk!usdsd1!dkowalsk
  2. From: dkowalsk@usdsd1.DaytonOH.NCR.COM (Dennis Kowalski)
  3. Newsgroups: comp.unix.shell
  4. Subject: Re: How to do $#a in Bourne shell?
  5. Message-ID: <1604@usdsd1.DaytonOH.NCR.COM>
  6. Date: 14 Sep 92 19:40:43 GMT
  7. References: <peter.716085132@merlin>
  8. Reply-To: dkowalsk@usdsd1.DaytonOH.NCR.COM (Dennis Kowalski)
  9. Organization: NCR USG Data Services Division
  10. Lines: 31
  11.  
  12. In article <peter.716085132@merlin> peter@merlin.acadiau.ca (Peter Steele)
  13. writes:
  14. >If I have a list in Bourne shell, how can I determine how many
  15. >elements are in, short of write a for loop and counting them?
  16. >Bourne shell doesn't seem to have C shell's $#variable construct.
  17. >It doesn't seem to support array indexing either, although I'm just
  18. >learning it and I might be missing something....
  19. >--
  20. >Peter Steele        Unix Services Manager            peter.steele@acadiau.ca 
  21. >Acadia Univ., Wolfville, NS, Canada B0P 1X0  902-542-2201  Fax: 902-542-4364
  22.  
  23.  
  24.  You did not say where your list was. If it is in a file with one list
  25. member per line such as :
  26.  
  27.   aaa
  28.   bbb
  29.   ccc
  30.  
  31.  try this
  32.  
  33.   CNT=`cat listfile | wc -l`
  34.  
  35.  The variable CNT will have the number of lines in "listfile"
  36.  
  37.  
  38. -- 
  39. Dennis Kowalski         NCR Corporation  PCD-3                  (513) 445-1843
  40. Systems Architecture    1700 S. Patterson Blvd              VOICEplus 622-1843
  41. USG Data Services Div   Dayton, Ohio     45479
  42. Dennis.Kowalski@DaytonOH.NCR.COM
  43.