home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.unix.questions
- Path: sparky!uunet!inmos!fulcrum!bham!warwick!pipex!mfmail!dnh
- From: dnh@mfltd.co.uk (Des Herriott)
- Subject: Re: How to recognize a csh var as a number?
- Message-ID: <1993Jan27.111224.1263@mfltd.co.uk>
- Sender: dnh@mfltd.co.uk (Des Herriott)
- Organization: Micro Focus Ltd., Newbury, UK
- References: <1jn3t3INN88b@haydn.crhc.uiuc.edu> <1993Jan26.231002.165645@dstos3.dsto.gov.au>
- Date: Wed, 27 Jan 1993 11:12:24 GMT
- Lines: 40
-
-
- In article <1993Jan26.231002.165645@dstos3.dsto.gov.au>, sct@tumtum (Shaun Troedson) writes:
- > Timothy Tsai (ttsai@crhc.uiuc.edu) wrote:
- > : I am reading string values into a csh variable. Depending on whether each
- > : string represents a number or not, I want to do certain things. How do I
- > : test to see if the variable string is a number or not?
- >
- > I think this works but its a mess:
- >
- > echo @ var = $var | csh -t >& /dev/null
- >
- > The status variable will now contain 1 if 'var' is alpha, 0 if it is num.
- > There's probably a less round-about way.
-
- Well, at the risk of starting a flame war, yes, there is: use a Bourne-derived
- shell. csh really is not suitable for shell programming, and only just about
- cuts it as a command-line interpreter.
-
- The above problem is simple if you use sh or (and undoubtedly bash too, though
- I haven't used it):
-
- case $variable in
- [0-9][0-9]*)
- # it's a number
- break;;
- *)
- # it's not a number
- esac
-
- See? No need to fork a new shell, no need to do any output redirection. It's
- all done by one process. I can't offhand think of a way of doing that in csh
- (and I used csh for 3 years before I saw the light :-)
-
- Des.
-
- --
- Des Herriott, / "...and I hate, and I hate, and I hate,
- Micro Focus, Newbury. / elevator music..."
- +44 (0635) 565354 /
- dnh@mfltd.co.uk / -- Tori Amos, Little Earthquakes.
-