How can you Test for bad number


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How can you Test for bad number
# 1  
Old 12-09-2005
How can you Test for bad number

Anyone know the code to test for bad numbers?

For example in ksh...
Want the user to input an integer, but they input characters.


read number
while (number = letter)
read number //until valid number is inputted

thx for any help!! Smilie
# 2  
Old 12-09-2005
Use egrep to test...

Code:
read foo
echo "${foo}" | egrep "^[0-9]+$" >/dev/null 2>&1
if [ "$?" -eq "0" ]; then
  echo "Yay"
else
  echo "Nay"
fi

Cheers
ZB
# 3  
Old 12-09-2005
This looks like a home work problem for me. Please read the Rules before posting.
Just a hint for your problem. Perform a arithmetic operation on your input. If it succeeds then numeric else it is non numeric.
# 4  
Old 12-09-2005
Thanks Bob
works great Smilie

Last edited by gsxpower; 12-09-2005 at 12:37 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

Bad magic number in disk label.

This is first time post...found this forum when looking for possible solution to fix my sun pc. Just one day can't boot it already showing the following: Boot device: disk File args: Bad magic number in disk label Can't open disk label package Evaluating: boot Can't open boot device... (40 Replies)
Discussion started by: SHuKoSuGi
40 Replies

2. Solaris

Bad magic number error

So we have a new to us v240 server with no OS installed. It has an outdated version of OB and ALOM so before we install the OS we want to update both. We have a DVD with the latest OB patch burned on it. We do the boot cdrom command but receive the Bad Magic Number Error. Does an OS need to... (2 Replies)
Discussion started by: dunkpancakes
2 Replies

3. Solaris

cpio: Bad magic number/header.

Hi, i got the following error while unpacking the archive file. cpio -icvd < as_sun_x86_101202_disk2.cpio Disk2/stage/Components/oracle.webdb.wwdoc/10.1.2.0.1/1/DataFiles/wwdoc.jar Disk2/stage/Components/oracle.webdb.wwdoc/10.1.2.0.1/1/DataFiles... (2 Replies)
Discussion started by: malikshahid85
2 Replies

4. Solaris

Solaris 8.2 Bad magic number

I'll keep it fairly straight forward. I work with a Solaris server and magically today it decided to take a dump on me. At first it give a long list of files that couldn't be acessed before terminating the boot process and returning to the 'ok' prompt. Booting in single-user mode allowed me to run... (4 Replies)
Discussion started by: Aon
4 Replies

5. Solaris

Bad File Number

System Solaris 8 When I open a CONSOLE window the following starts scrolling: "ServiceCommand: :write: Bad FIle Number" This will continue to scroll without stopping. However, you can type while it is scrolling and login into root and even conduct business within the CONSOLE window. The... (1 Reply)
Discussion started by: Kevin1166
1 Replies

6. Shell Programming and Scripting

Bad day !! test condition failed --need a one liner to do --help

Hi all this is simple but bad day for me nothing work out .. Problem is that I wan to check the argument passed to my script and accordignly exit or setup ENV variable I have a script name src_cpcp_preproc.sh i want to pass 2 argumet from command line argumet and check it in the script... (13 Replies)
Discussion started by: jambesh
13 Replies

7. UNIX for Advanced & Expert Users

Bad Number Error

What is wrong with my syntax, I am getting bad number error. The following lines of code get the value from INI file but the variable is a combination of multiple variables. When compiling all together, I get a bad number error or changing the '((' with '{{' gets me bad substitution error. The... (2 Replies)
Discussion started by: moan71
2 Replies

8. Filesystems, Disks and Memory

Bad Magic Number

Dear All, i have a SCSI hard disk drive i'm installing on it solaris 5 and the workstation is sun sparc, i made an image of this H.D using Norton Ghost 6, so i took off the SCSI H.D from the sun workstation and put it on a Compaq server then i booted the server from the Norton Ghost floppy disk... (0 Replies)
Discussion started by: wesweshahaha
0 Replies

9. Shell Programming and Scripting

bad if test

:confused: Bad if test: if returns an error I have changed filename to "filename"s su "$filename" 'filename'' '$filename'' "./filename" "./$filename" error is usually why cant I test the filename? Thanks (4 Replies)
Discussion started by: sharkze
4 Replies

10. UNIX for Advanced & Expert Users

bad magic number

Hi, when installing a piece of third part software I get the error "Bad magic number" at one point when it tries to use libraries from the bea tuxedo server. Am I correct that this means that the software is expecting 32bit while I'm on 64bit? Is there a way around it or can it only be solved... (5 Replies)
Discussion started by: rein
5 Replies
Login or Register to Ask a Question