|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here! |
|
#1
|
|||
|
|||
|
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 |
|
#2
|
|||
|
|||
|
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 |
![]() |
| Viewing: Dev Shed Forums > Operating Systems > UNIX Help > I was forced to quit :( |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|