SunQuest
           UNIX Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOperating SystemsUNIX Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here!
  #1  
Old August 23rd, 2004, 09:36 PM
superduper superduper is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2000
Location: hk
Posts: 4 superduper User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I was forced to quit :(

halo,

I have a C-shell script below to let user input an integer. It's ok but if you enter a string like "abd", the program will quit with a mesage @: Expression syntax. How can I check that a user enters a string ? Or can I control my script not to quit even a user enters anything other than integer ?


#!/usr/bin/csh -f
echo -n "Please input an interger and it will be shown in minute --> "
@ yourNum = $<

set myVar = $yourNum
echo $myVar | egrep -s '^[-+]?([0-9]+\.[0-9]+|[0-9]+\.|\.[0-9]+|[0-9]+)([eE][-+]
?[0-9]+)?$'

if (! $status) then
echo "input is numeric"
endif

@ num = $myVar
if ( $num < 0 ) then
echo "Number cannot be less than zero"
else
@ showInMin = $num / 60
@ showInSec = $num % 60
echo "This is min " $showInMin
echo "This is sec " $showInSec
endif

Reply With Quote
  #2  
Old August 24th, 2004, 01:33 AM
guggach guggach is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jul 2004
Location: Middle Europa
Posts: 1,083 guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 4 Days 19 h 49 m 57 sec
Reputation Power: 9
don't write csh-scripts, it's buggy.
use sh , it's easy, stable and sure runs on all *nix.
ksh and bash are also alternatives.

Code:
while .
do
   read num
   case ${num:=q} in q) break
   ;;            [0-9]*[0-9]) 
   ;;                           *) echo error; continue
   ;; esac
   # shell is not the tool 4 arithm. computing...
   set `echo "$num % 60; $num / 60" | bc`
   echo sec=$1 min=$2
done

Last edited by guggach : August 24th, 2004 at 01:34 AM. Reason: typo

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > I was forced to quit :(


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway