home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!mcsun!uknet!siesoft!wstuart!stuart
- From: stuart@wstuart (Stuart Hood)
- Newsgroups: comp.unix.shell
- Subject: Re: How to do $#a in Bourne shell?
- Message-ID: <1992Sep10.161610.9882@siesoft.co.uk>
- Date: 10 Sep 92 16:16:10 GMT
- References: <peter.716085132@merlin>
- Sender: news@siesoft.co.uk (Usenet News)
- Organization: Siemens Nixdorf Information Systems Ltd.
- Lines: 23
- X-Newsreader: Tin 1.1 PL4
-
- peter@merlin.acadiau.ca (Peter Steele) writes:
- : If I have a list in Bourne shell, how can I determine how many
- : elements are in, short of write a for loop and counting them?
- : Bourne shell doesn't seem to have C shell's $#variable construct.
- : It doesn't seem to support array indexing either, although I'm just
- : learning it and I might be missing something....
-
- I think the best way to deal with lists in Bourne Shell is to
- use the set command. For example, suppose you want to count
- how many items are in the PATH list:
-
- #!/bin/sh
- IFS=:
- set $PATH
- echo $#
- exit 0
-
- Stuart
- -
- --
- S I E M E N S Stuart Hood === Siemens Nixdorf House, Bracknell, Berks, UK
- ------------- Phone: + 44-344-850892 Email: stuart@siesoft.co.uk
- N I X D O R F - Never let ignorance stand in the way of a good argument -
-