Results 1 to 2 of 2
Hello all. I am currently writing a TCSH script that takes three numerical arguments (these are supposed to be sides of a triangle) and tells the user if the triangles ...
- 09-21-2008 #1Just Joined!
- Join Date
- Sep 2008
- Posts
- 1
TCSH Script
Hello all. I am currently writing a TCSH script that takes three numerical arguments (these are supposed to be sides of a triangle) and tells the user if the triangles is scalene, equilateral, isosceles, right triangle, or not a triangle. My first problem is that the program isn't supposed to take non-numerical input, and I can't use anything but TCSH to write this (no I really wish I could use BASH or Perl to do this.) I guess TCSH has no built in way of detecting if a string is numeric or not (it sounds like TCSH scripting just sucks anyways), so I decided the best way to do it is to try:
Which of course doesn't work...Code:@ argvnum = 1 while ( $argvnum <= $#argvnum ) @ check = $argv[argvnum] >& tempfile if ( cat tempfile == '@: Expression Syntax.' ) then echo "Non-numerical input given for argument $argvnum." echo "3 numerical sides needed for arguments." endif @ argvnum++ end
So I guess my question is, since theres no way I know of to determine if a variable string is a number and get an error output understandable to an average user, how can I take the text contents of a file and input it into a string? Is there a better way to do what I am trying to do above? Also what command forces the script to quit (since I don't want it to go any further if it detects a argument that isn't a number)?
- 09-21-2008 #2Linux Engineer
- Join Date
- Apr 2006
- Location
- Saint Paul, MN, USA / CentOS, Debian, Solaris, SuSE
- Posts
- 1,117
Hi.
This seems to be homework, such as for CS 155: Intro to Unix | Main / HW4
Posting homework questions violates the forum rules: http://www.linuxforums.org/forum/lin...ums-rules.html
I suggest reading the man page to see if there are features in tcsh that would help you.
If this is not homework, then perhaps there is a better tool to use ... cheers, drlWelcome - get the most out of the forum by reading forum basics and guidelines: click here.
90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
We look forward to helping you with the challenge of the other 10%.
( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )


