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

  1. Path: sparky!uunet!mcsun!uknet!siesoft!wstuart!stuart
  2. From: stuart@wstuart (Stuart Hood)
  3. Newsgroups: comp.unix.shell
  4. Subject: Re: How to do $#a in Bourne shell?
  5. Message-ID: <1992Sep10.161610.9882@siesoft.co.uk>
  6. Date: 10 Sep 92 16:16:10 GMT
  7. References: <peter.716085132@merlin>
  8. Sender: news@siesoft.co.uk (Usenet News)
  9. Organization: Siemens Nixdorf Information Systems Ltd.
  10. Lines: 23
  11. X-Newsreader: Tin 1.1 PL4
  12.  
  13. peter@merlin.acadiau.ca (Peter Steele) 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. I think the best way to deal with lists in Bourne Shell is to
  21. use the set command.  For example, suppose you want to count
  22. how many items are in the PATH list:
  23.  
  24. #!/bin/sh
  25. IFS=:
  26. set $PATH
  27. echo $#
  28. exit 0
  29.  
  30. Stuart
  31. -
  32. --
  33. S I E M E N S  Stuart Hood === Siemens Nixdorf House, Bracknell, Berks, UK
  34. -------------  Phone: + 44-344-850892          Email: stuart@siesoft.co.uk
  35. N I X D O R F  - Never let ignorance stand in the way of a good argument -
  36.